问题
I have table in SQL Server which contains a column of type "int". The column can contain positive as well as negative values. I want to carry out sorting based on this column values such that rows with positive values in this column come before the negative values.
Example:
Code SortColumn
A 1
B 5
C -1
D -3
E 0
F 2
Desired Output:
Code SortColumn
E 0
A 1
F 2
B 5
C -3
D -1
回答1:
Select * from Table
order by
Case when sortcolumn<0 then 1 else 0 end
,sortcolumn
来源:https://stackoverflow.com/questions/14908147/orderby-in-sql-server-to-put-positive-values-before-negative-values