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

前端 未结 4 664
说谎
说谎 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 05:55

    The following query should do the trick.

    (SELECT * FROM table WHERE num!=0 ORDER BY num) UNION (SELECT * FROM table WHERE num=0)
    

提交回复
热议问题