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.
精彩评论