Mahee
Mahee

Reputation: 63

SQL Rank syntax for using multiple columns to rank by

I am trying to do ranking based on 2 columns and also when it comes to a tie, differentiate them based on the other column.I have put together the below table to explain my question. So I want to rank the players based on their scores per game with in their team, and if they come to a tie, I want to rank them based on their scores per year, still within their team. How can I achieve that with a sql query? Any help is appreciated. Thank you in advance! base tableexpected result

Upvotes: 2

Views: 1537

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1269753

You seem to want:

rank() over (partition by team order by scores_per_game desc, scores_per_year desc)

Upvotes: 1

Related Questions