I am trying to build a MySQL query that has an order by statement. This is what I am trying to do:
SELECT *
FROM tbl_product
ORDER BY retail_price ONLY IF wholesale_price IS NULL O开发者_运维知识库THERWISE ORDER BY wholesale_price.
I have no idea where to start. I found an article that uses ORDER BY COALESCE but I also found that this could have performance issues.
Any advice is appreciated.
SELECT *
FROM tbl_product
ORDER BY ifnull(wholesale_price, retail_price);
Note that you don't need to select the value you're ordering by - it can be any expression
精彩评论