MySQL Query ORDER BY certain values before others

a 夏天 提交于 2019-12-30 22:59:09

问题


I am developing a game highscore where the time of completion is stored in a database, but if you don't complete the level but save your highscore, the completion time is 0.

I am trying to make a query which lists the highscore with the lowest completion time first, but my simple ORDER BY is sticking all of the 0 completion times at the start of course!

Is there any way I can order it like this, but have the 0's at the bottom.

I have tried:

SELECT FROM highscores ORDER BY completiontime > 0, completiontime = 0 ASC

Anyone have any ideas?


回答1:


SELECT *
FROM highscores
ORDER BY completiontime = 0, completiontime


来源:https://stackoverflow.com/questions/4371193/mysql-query-order-by-certain-values-before-others

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!