开发者

sorting by value specific - ORDER BY

I am开发者_C百科 trying to sort a query using ORDER BY where I need to sort 3 columns one by one. And the third column is value specific.

Eg: If i have 3 columns a,b and c I need to use ORDER BY a, b desc, c='3' asc, c

What I want to do is first sort order is a, then b in desc order then I want the values of which has 3 to be sorted and then the remaining values which are not 3.


 ORDER BY
  a,
  b desc,
  CASE WHEN c = 3 THEN 0 ELSE 1 END,
  c


Assuming SQL Server, try using CASE:

ORDER BY a, b desc, CASE c WHEN '3' THEN 0 ELSE 1 END, c ASC


ORDER BY
a,
b desc,
CASE c when 3 then 1 else 0 end
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜