Reputation: 107
I have a weird situation where i need to order 0 first and then descends a column.
Let's say i have column that looks like this
Status
------
3
4
0
5
1
2
4
0
2
And Now i need to order it by
Status
------
0
0
5
4
4
3
2
2
1
Is this possible for SQL? I've been trying to test for 2 days now but i am stuck.
Upvotes: 2
Views: 7062
Reputation: 44796
Use a case
expression to first sort 0's and then the rest. After that sort by status desc:
order by case when Status = 0 then 0 else 1 end, status desc
Upvotes: 14