我想查询MotoGP Race结果中的排名
我的sql是
SELECT `Rider`, `Team`, `Bike`,SUM(`Points`)
FROM `table_name`
WHERE `Year` = 2015 AND `Classes` = "MotoGP"
GROUP BY `Year`,`Rider`
HAVING SUM(`Points`)
ORDER BY SUM(`Points`) DESC
如果2个或更多骑手具有相同的SUM('Points'),则下一个顺序是第1个比赛位置的数量。 我把比赛位置放在'Pos'字段上。
Pos值:1,2,3,4,5 ......
请帮助完成第二个订单。谢谢
答案 0 :(得分:0)
您只需要更改HAVING
子句:
ORDER BY SUM(`Points`) DESC,
SUM(RacePosition = 1) DESC
对于多个职位,我认为您需要为每个职位添加条件:
ORDER BY SUM(`Points`) DESC,
SUM(RacePosition = 1) DESC,
SUM(RacePosition = 2) DESC,
SUM(RacePosition = 3) DESC
在某些时候,或许SUM(RacePosition)
会做你想做的事。