gpt4 book ai didi

sql-server - SQL Server 中的排序顺序

转载 作者:行者123 更新时间:2023-12-02 06:24:20 26 4
gpt4 key购买 nike

我能否更改 SQL Server 数据库中的默认排序顺序,以便最后显示空值和零长度字符串。

它的 SQL Server 2000

我强调,如果可能的话,我想更改所有查询的默认顺序

最佳答案

您几乎可以在 order by 中使用 case 进行任何排序。这里首先是 null 列,然后是空字符串,其余的按 col1 和 col3 排序:

select  *
from YourTable
order by
case when col1 is null then 1
when col1 = '' then 2
else 3
end
, col2
, col3 desc

关于sql-server - SQL Server 中的排序顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3574284/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com