SQL: How can I order null and empty entries to the front in an orderby?

后端 未结 4 1174
逝去的感伤
逝去的感伤 2021-01-02 08:24

If I have the following entries in my database:

ID Name
1 [null]
2 [empty string]
3 Alpha
4 Bravo
5 Charlie

..then how can I order

4条回答
  •  北荒
    北荒 (楼主)
    2021-01-02 09:19

    ORDER BY (CASE WHEN Name IS NULL THEN 1 WHEN Name IS NULL THEN 2 ELSE 3 END) DESC

提交回复
热议问题