realkes
realkes

Reputation: 881

ranking the rows in sql

What I want to do is to understand the order per location. Does anyone know how to solve the issue?

class   grade   location rank
A       21       G         3
A       22       H         2
A       23       F         1
B       27       G         1
B       25       H         2
B       24       F         3
C       22       G         3
C       28       H         2
C       29       F         1

Upvotes: 0

Views: 28

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1269513

You would use rank():

select t.*, rank() over (partition by year order by grade desc) as seqnum
from t;

Upvotes: 1

Related Questions