i have a question about a query in MySQL i am trying to do. Suppose i have the following table:
Table: Products
ID | Name | Price | Price_mode |
0 | product1 | 150 | 1 |
1 | product2 | 5 | 2 |
2 | product3 | 8 | 2 |
And i want to order the products by price
DESC but if price_mode
is "2", i want the price to be multiplied by a number, say 20 for example.
With this criteria, the table should be ordered like: product3, product1, product2.
I hope you understood my question and thanks ! :)
You can do this with expressions in the order by
:
order by (case when price_mode = 2 then price * 20 else price end) desc