Weird Results on MySQL SELECT Statement with ORDER BY
I'm getting weird results on a MySQL SELECT statement that uses ORDER BY my_column ASC.
It's ordering the results the way a "computer" would order them, instead of a human:
- Item F: 241.565853
- Item B: 25.310854开发者_如何转开发
- Item D: 25.397155
- Item C: 260.252356
- Item A: 27.7740
- Item E: 271.774058
How do I get it to ORDER BY in the correct manner? My SELECT statement has a couple LEFT JOINS-- not sure if that would make a difference.
Any suggestions on how to correct this problem?
Something like this should do it:
ORDER BY ABS(my_column) ASC
The column you're ordering by is most likely a string-based (varchar, text, etc) datatype. You're seeing lexically-correct ordering for such a datatype. Change the column to use a numeric datatype, or (less-preferably, because why are you storing a numeric value as a string) cast the column to a numeric type and perform the sort on that cast.
精彩评论