sql - How can I sort a field in numerical order after FORMAT() in MySQL? -


after using format() strip unnecessary decimal places result, i'm unable correctly order field, field string rather number.

what practice order results , remove decimal places (or vice versa) ordered in correct numerical order?


results before format

order `field` asc  *---------* | 1000.06 | | 2000.17 | | 3000.12 | | 10000.4 | | 20000.1 | | 30000.2 | *---------* 

results sorted numerically there unneeded decimal places need removed.


results after format()

order `field` asc     *---------* | 1,000   | | 10,000  | | 2,000   | | 20,000  | | 3,000   | | 30,000  | *---------* 

results have had decimal places removed format() has made field string not sorting numerically require, alphabetically.


required results

*---------* | 1,000   | | 2,000   | | 3,000   | | 10,000  | | 20,000  |  | 30,000  | *---------*  

the required result results sorted numerically , have decimal places removed.

just select formatted value , order unformatted one.

select format(value, 0) t order value asc 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -