I can't find a way to sort a varchar column casted as float. Here is my SQL request:
SELECT guid, number FROM table ORDER BY 'CAST(number AS FLOAT) DESC'
The "number" column is defined like this:
number varchar(20) ascii_general_ci
And the values defined in this column for my test are :
0.00
200.00
20.00
100.00
MySQL totally ignore the CAST operator and sort the columns by guid...
Is there a bug in MySQL or did I do something wrong ?
Try this trick (helps to sort strings as numbers)-
SELECT guid, number FROM table ORDER BY number * 1 DESC
It will help MySQL to cast string to number.
Another solution -
...CAST(value as DECIMAL(10,5))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With