Possible to use SQL to sort by date but put null dates at the back of the results set?

前端 未结 4 764
萌比男神i
萌比男神i 2021-01-31 01:53

I have a bunch of tasks in a MySQL database, and one of the fields is \"deadline date\". Not every task has to have to a deadline date.

I\'d like to use SQL to sort the

4条回答
  •  盖世英雄少女心
    2021-01-31 02:16

    Here's a solution using only standard SQL, not ISNULL(). That function is not standard SQL, and may not work on other brands of RDBMS.

    SELECT * FROM myTable
    WHERE ...
    ORDER BY CASE WHEN myDate IS NULL THEN 1 ELSE 0 END, myDate;
    

提交回复
热议问题