开发者

MySQL Sorting Ranking List with positon 0

I am trying to sort a ranking list of sports players, all of which have a ranking pos开发者_开发知识库ition. However, some are new on tour, so their ranking is 0. If I simply order by position ASC the 0's will appear first, I would like them to appear after the rest. I have tried something like:

SELECT * FROM rankings WHERE season='$season' ORDER BY CASE position = 0 THEN 999, ELSE position ASC


You can handle it strictly in the ORDER BY clause

SELECT * 
FROM rankings 
WHERE season='$season' 
ORDER BY (position=0) ASC, position ASC


try this:

SELECT *, (CASE position WHEN 0 THEN 999 ELSE position) AS custom_sort FROM rankings WHERE season='$season' ORDER BY custom_sort ASC
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜