问题
How can i apply mysql MIN() over mixed decimal value and scientific notation values. I need to get minimum distance using latitude longitude equation in a mysql query with MIN(). It is working if the distance are decimal. But it is not working properly, if some distance are too small like "5.89872212195226e-05"
The problem is MIN(4,5.89872212195226e-05) in a mysql query will always return '4'.
Here is the part of query
MIN (
(acos(sin((".$searchLat."*pi()/180)) *
sin((b_loc.locLatitude*pi()/180))+cos((".$searchLat."*pi()/180)) *
cos((b_loc.locLatitude*pi()/180))
* cos(((".$searchlng."- b_loc.locLongitude)*pi()/180))))*180/pi())*60*1.1515
) as mindistance
Any solution? Thank You
回答1:
Cast to decimal should help :-
mysql> select cast( "5.89872212195226e-05" as decimal(65,30)); +--------------------------------------------------+ | cast( "5.89872212195226e-05" as decimal(65,30)) | +--------------------------------------------------+ | 0.000058987221219522600000000000 | +--------------------------------------------------+
Example of comparison :-
mysql> select least( 4, cast("5.89872212195226e-05" as decimal(65,30)) ); +------------------------------------------------------------+ | least( 4, cast("5.89872212195226e-05" as decimal(65,30)) ) | +------------------------------------------------------------+ | 0.000058987221219522600000000000 | +------------------------------------------------------------+
Example usage :-
MIN(cast( ... as decimal(65,30)))
来源:https://stackoverflow.com/questions/8356104/how-to-compare-scientific-notation-and-decimal-numbers-in-mysql-min-aggregate