开发者

MySQL IFNULL on 4 or 5 columns

I have a statement that is:

ORDER BY IFNULL(rrp, wholesale) ASC

...but I wanted to know if there开发者_如何学Python is a way to have an IFNULL statement that checks 3 or 4 or 5 columns? All from the same table.


Use COALESCE

e.g:

SELECT ....
  FROM ....
ORDER BY COALESCE(rrp, wholesale, column3, column4)


You could chain them up, so the expression picks the first not-null value from a list of columns:

ORDER BY IFNULL(IFNULL(IFNULL(rrp, wholesale), some_column), some_other_column) ASC


Try using COALESCE; it may give you what you need.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜