PostgreSQL - conditional ordering

后端 未结 1 572
失恋的感觉
失恋的感觉 2021-01-18 02:23

I have the following table:

key | date         | flag
--------------------------
1    now()           true
2    now() - 1 hour  true
3    now() + 1 hour  tru         


        
相关标签:
1条回答
  • 2021-01-18 03:07

    conditional order can be performed with CASE, like here:

    select *
        from test
    order by 
        flag
      , case when flag then date end desc
      , case when not flag then date end asc
    
    0 讨论(0)
提交回复
热议问题