SQL select query order by day and month

后端 未结 4 978
长情又很酷
长情又很酷 2021-01-22 10:17

Let\'s pretend today is the 3rd of February.

And I have a table:

CREATE TABLE devotion
(
  id serial NOT NULL,
  date timestamp without time zone
}
         


        
4条回答
  •  执笔经年
    2021-01-22 10:44

    Simpler:

    ORDER BY (date1 < now()), date1
    

    You can just order by the boolean value of the expression (date1 < now()).
    FALSE sorts before TRUE sorts before NULL.

提交回复
热议问题