mysql order by,先为null,后为DESC [英] mysql order by, null first, and DESC after
本文介绍了mysql order by,先为null,后为DESC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何按字段排序DESC,但首先列出NULL值?
How can I order DESC by a field, but list the NULL values first?
所以我有一张桌子:
reuestId | offerId | offerTitle
1 | 1 | Alfa
NULL | 2 | Beta
2 | 3 | Gamma
我想选择它们,以便结果为:
I want to select them so that the results would be:
NULL | 2 | Beta
2 | 3 | Gamma
1 | 1 | Alfa
推荐答案
尝试一下:
ORDER BY [reuestId] IS NULL DESC, [reuestId] DESC
(适用于mySql)应该工作
should work (for mySql)
这篇关于mysql order by,先为null,后为DESC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文