开发者

MySQL Query order by if null

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜