Unlimited Web Space

Enjoy Unlimited web hosting

Sep 28, 2011

How to add a rank to a column that has multiple values w.r.t another column?

Here, I have data(T1) like this,



C1    C2    C3
1      11      A
2      11      B
3      12      C
4      12      C

I want to display a column (Rank of C2) that will display the rank of C2 based on the column C1 and get the result as,


C1    C2    C3    Rank
1      11     A      1
2      11     B      2
3      12     C      1
4      12     C      2

select C1,C2,C3,
ROW_NUMBER() over(partition by C2 order by C1) as Rank
from T1

No comments:

Post a Comment