mysql - SQL Multi Order by Count with Criteria -
i want query standings motogp race result
my sql
select `rider`, `team`, `bike`,sum(`points`) `table_name` `year` = 2015 , `classes` = "motogp" group `year`,`rider` having sum(`points`) order sum(`points`) desc
if 2 or more riders have same sum('points'), next order number of 1st race position. put race position on 'pos' field.
pos value: 1,2,3,4,5 ...
please 2nd order. thank you
you need change having
clause:
order sum(`points`) desc, sum(raceposition = 1) desc
for multiple positions, think need add condition each one:
order sum(`points`) desc, sum(raceposition = 1) desc, sum(raceposition = 2) desc, sum(raceposition = 3) desc
at point, perhaps sum(raceposition)
want.
Comments
Post a Comment