How can I ORDER BY according to some boolean logic?

后端 未结 3 918
感动是毒
感动是毒 2021-01-26 07:17

Say I have columns \'a\' and \'b\'. A record is deemed \'ready\' if !a || b. How can I sort by this ready condition? I\'m really rusty with SQL and I can\'t reca

相关标签:
3条回答
  • 2021-01-26 07:55

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

    0 讨论(0)
  • 2021-01-26 08:07

    You can put expressions in the ORDER BY clause.

    ORDER BY (!a || b) ASC
    
    0 讨论(0)
  • 2021-01-26 08:09
    order by case when !a || b then 0 else 1 end
    
    0 讨论(0)
提交回复
热议问题