Using MySql, can I sort a column but have 0 come last?

前端 未结 4 681
说谎
说谎 2020-12-24 05:38

I want to sort by an column of ints ascending, but I want 0 to come last. Is there anyway to do this in MySql?

4条回答
  •  难免孤独
    2020-12-24 06:03

    You can do the following:

    SELECT value, IF (value = 0, NULL, value) as sort_order
    FROM table
    ORDER BY sort_order DESC
    

    Null values will be down of the list.

提交回复
热议问题