php - MySQL query on money format -


i got table prices has values similar following:

price -----------  21,781.00 27,615.00 46,565.00 46,565.00 48,565.00 571.00 830.00 0.00 

by doing query:

select * tprice order price=0, convert(price, decimal) asc 

i following result:

21,781.00 27,615.00 46,565.00 46,565.00 48,565.00 571.00 830.00 

and, doing query:

select * tprice order price=0, convert(price, decimal) desc 

i

830.00 571.00 48,565.00 46,565.00 46,565.00 27,615.00 21,781.00 0.00 

why 830.00 , 571.00 not been ordered properly?

edit:

i've changed query to:

select * tprice order price=0, replace(',','',price), price asc 

it seems working "a bit better". result:

830.00 571.00 48,565.00 46,565.00 46,565.00 27,615.00 21,781.00 0.00 

still trying other variations...

select price, convert(replace(replace(price, ",", ""), ".", ""),unsigned integer) formattedprice testtest order formattedprice; 

this should work.

explanation: saved numbers string in database. removing except numbers , converting unsigned int solves problem.


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -