php - How do I execute a query with an advanced ORDER BY situation? -
I have a question about a query in MySQL which I am trying to do. Suppose i have the following table:
table: product
id | Name | Price | Value_mode | 0 | Product 1 | 150 | 1 | 1 | Product 2 | 5 | 2 | 2 | Product3 | 8 | 2 |
And if I want to order products by value
DESC but by price_mode
"2" , Then I want the value to be multiplied by a number, say 20 for example.
With this criterion, the table order should be ordered: product3, product1, product2.
I hope you understand my questions and thanks! :
You can do this with expression in order
: <: >
command (when price_mode = 2 then price * 20 other price end) desc
Comments
Post a Comment