2012-08-08

TSQL - Dense rank vs rank vs row number


select
       T1.Field1
       , DENSE_RANK() over( order by Field1 asc ) as DenseRank
       , RANK() over( order by Field1 asc ) as DenseRank
       , ROW_NUMBER() over( order by Field1 asc ) as RowNumber
from
       (
              select 'a' as Field1
              union all select 'a'
              union all select 'a'
              union all select 'b'
              union all select 'b'
              union all select 'c'
              union all select 'd'
       ) as T1
;

No comments:

Post a Comment