In a column I have something like this:
Amount:
12
2x25
192
How is it possible to multiply in this example 2x25 to order it correctly ASC.
My starting point:
SELECT * FROM table
ORDER BY REPLACE(Amount,'x','*') ASC
TIA frgtv10
In a column I have something like this:
Amount:
12
2x25
192
How is it possible to multiply in this example 2x25 to order it correctly ASC.
My starting point:
SELECT * FROM table
ORDER BY REPLACE(Amount,'x','*') ASC
TIA frgtv10
try this
SELECT
CAST(if(Amount LIKE '%x%', SUBSTRING_INDEX(Amount, 'x', 1) *
SUBSTRING_INDEX(Amount, 'x', -1) , Amount) as unsigned ) as amount
FROM table1
ORDER BY Amount ASC
steps and explaining :
locate fields with x value
sbstring from left and right and multiply it.
then cast the multiplication as unsigned.
order it asc