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)-
It will help MySQL to cast string to number.
Another solution –