SQL Server 相当于 Oracle 的 NULLS FIRST? [英] SQL Server equivalent to Oracle's NULLS FIRST?

查看:26
本文介绍了SQL Server 相当于 Oracle 的 NULLS FIRST?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以 Oracle 有 NULLS FIRST,我可以使用它将空值排在顶部,然后按降序排列我的列值:

So Oracle has NULLS FIRST, which I can use to have null values sorted at the top followed by my column value in descending order:

ORDER BY date_sent NULLS FIRST

SQL Server 中的可比性是什么?假设日期值为 NULL 或过去,有这些替代方案:

What is comparable in SQL Server? There are these alternatives, assuming the date values are NULL or in the past:

ORDER BY ISNULL(date_sent, GETDATE()) DESC
ORDER BY (CASE WHEN t.setinactive IS NULL THEN 1 ELSE 2 END), t.setinactive DESC
ORDER BY -CAST(date_sent as int) ASC

还有其他的吗?

推荐答案

你可以做些小动作:

ORDER BY (CASE WHEN [Order] IS NULL THEN 0 ELSE 1 END), [Order] 

这篇关于SQL Server 相当于 Oracle 的 NULLS FIRST?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆