开发者

How do I write a query with a conditional order by?

开发者 https://www.devze.com 2023-03-26 09:48 出处:网络
I currently have a 开发者_StackOverflowquery that is built based on order details passed from a POST method. I also need to have a default order in addition that kicks records to the end of the result

I currently have a 开发者_StackOverflowquery that is built based on order details passed from a POST method. I also need to have a default order in addition that kicks records to the end of the results that have one of two fields equal to specific values, respectively.

Basically, despite the passed dynamic order, if a record's status_hold is not null OR stage_num=17 then the record needs to be at the end of the list.


You can use a case statement as part of your sort:

order by case when status_hold is not null OR stage_num=17 then 1 else 0 end
0

精彩评论

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