7
I have a table in MYSQL (can be seen here http://sqlfiddle.com/#! 9/187ce/1 ), where the price is with commas and not points:
2.00 2,33 11.00
When I’m going to give an order by:
ORDER BY preco ASC
The system understands that it is a string and puts the 11.00 in front, how to make this conversion to number at the time of ORDER BY?
Just to tell you, I can’t modify the table, it’s not mine and I don’t have that permission.
this value could be a decimal?
– novic
@Virgilionovic yes, I need to turn to decimal 1.00 to 1.00, 2.33 to 2.33 (basically replacing the virgukla by dot would already make it interpret as number, no?
– caiocafardo
Hello, put your table create here.
– Cléverton Heming
If the value is numerical, the solution is to fix the DB. Very rare a situation where the data must be stored in the display format (in your case, obviously not appropriate). It is usually a basic architecture failure to store dates and numbers as a string, which generates a whole series of disadvantages.
– Bacco
Two answers appeared that work, but it is worth leaving a warning: the ideal is to have a column of the right type, preferably with index, and sort by it. Conversions and Places on the fly will certainly affect query performance (which may or may not be a problem in your case).
– bfavaretto
But man, if you’re gonna use this field for calculations and values, I think you better switch to the field type. Avoid these problems of conversions and inconvenience
– GabrielLocalhost
@Gabriellocalhost would be the ideal world, but I don’t have that permission, only if I take the entire customer table and copy it to a new table, but what if he inserts new products? I’d have to keep updating this with a cronjob... but I wasn’t hired to do it...
– caiocafardo