我正在尝试排序体育运动员的排名列表,所有这些都有排名位置。然而,有些是巡回赛中的新手,所以他们的排名是0.如果我只是按位置ASC排序,0将首先出现,我希望它们出现在其余的之后。我尝试过类似的东西:
SELECT * FROM rankings WHERE season='$season' ORDER BY CASE position = 0 THEN 999, ELSE position ASC
答案 0 :(得分:2)
您可以在ORDER BY
子句
SELECT *
FROM rankings
WHERE season='$season'
ORDER BY (position=0) ASC, position ASC
答案 1 :(得分:0)
试试这个:
SELECT *, (CASE position WHEN 0 THEN 999 ELSE position) AS custom_sort FROM rankings WHERE season='$season' ORDER BY custom_sort ASC