我有以下查询:
select *
from tbl1
order by date1 DESC
当我这样做时,date1
的空值显示在底部。如何让它们显示在顶部,然后订购具有值 DESC 的那些?
您可以通过使用 case 表达式来确定date1
是否为 null 并首先按此进行排序来执行此操作。
select *
from tbl1
order by case when date1 is null then 1 else 0 end desc, date1 DESC
另一种选择是使用isnull
:
SELECT ColumnsList
FROM tbl1
ORDER BY ISNULL(date1, '2525-12-31') DESC