SQL如何在升序排序时使空值排在最后 [英] SQL how to make null values come last when sorting ascending
本文介绍了SQL如何在升序排序时使空值排在最后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个带有日期时间字段的 SQL 表.有问题的字段可以为空.我有一个查询,我希望结果按日期时间字段升序排序,但是我希望日期时间字段在列表末尾而不是开头的行为空.
I have a SQL table with a datetime field. The field in question can be null. I have a query and I want the results sorted ascendingly by the datetime field, however I want rows where the datetime field is null at the end of the list, not at the beginning.
有没有一种简单的方法可以做到这一点?
Is there a simple way to accomplish that?
推荐答案
select MyDate
from MyTable
order by case when MyDate is null then 1 else 0 end, MyDate
这篇关于SQL如何在升序排序时使空值排在最后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文