sql RANK DENSE RANK

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sql RANK DENSE RANK相关的知识,希望对你有一定的参考价值。


Select RANK() over( order by col1) colnam1
Select Dense_rank() over(order by col1) colnam2


Select RANK() over( partition by col2 order by col1) colnam1
Select Dense_rank() over(partition by col2 order by col1) colnam2


Difference between rank, denserank, rowno
RANK() returns 1,1,3,4
DENSE_RANK() returns 1,1,2,3
ROW_NUMBER() returns 1,2,3,4


NTILE() OVER( partition by col2 order by col1 desc)

LEAD(col1) over (partition by col2 order by col1 desc)
LEAD(col1,2,-1) over (partition by col2 order by col1 desc)

##leading by 2 rows. default value -1

FIRST_VALUE(zipcode) over(order by order_date)


sum(salary) over (partition by gender)

## will have effect of grouping by

sum(salary) over(order by salary desc)
## will create running total












以上是关于sql RANK DENSE RANK的主要内容,如果未能解决你的问题,请参考以下文章

sql排序对比(row_number,rank,dense_rank)

SQL - 一起使用dense_rank和group by

sql 中 rank() over,dense_rank(),row_number() 的区别

T-SQL“dense_rank”,每个等级的最大行数

sql Teradata的DENSE_RANK

SQL SERVER 的窗体函数OVER的使用:row_number/rank/dense_rank