我在 SQL Server 中有一个表,其中包含“int”类型的列。该列可以包含正值和负值。我想根据该列值进行排序,使得该列中具有正值的行排在负值之前。
示例:
Code SortColumn
A 1
B 5
C -1
D -3
E 0
F 2
期望的输出:
Code SortColumn
E 0
A 1
F 2
B 5
C -3
D -1
最佳答案
Select * from Table
order by
Case when sortcolumn<0 then 1 else 0 end
,sortcolumn
关于sql - SQL Server 中的 Order By 将正值放在负值之前,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14908147/