开发者

How can I ORDER BY according to some boolean logic?

Say I have columns 'a' and 'b'. A record is deemed 'ready' if !a || b. Ho开发者_JS百科w can I sort by this ready condition? I'm really rusty with SQL and I can't recall what would have been the best way to do this. My guess is that I would be able to add a column with the boolean result and then sort by that column, but I've tried searching and can't seem to find what I'm looking for.


order by case when !a || b then 0 else 1 end


You can put expressions in the ORDER BY clause.

ORDER BY (!a || b) ASC


So you just want all rows where !a or b is true first? If so order by !a and then by b.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜