常见的数据库记录
发布时间
阅读量:
阅读量
常用指令
oracle
数据连接

窗口函数over()应用分析
窗口函数中over()函数常涉及两个关键属性,即partition by与order by。其中,partition by的作用类似于group by,通常将group by称为分组操作,而partition by则被称为分区操作。分组操作一般返回单行结果,而分区操作则会返回多行数据。
窗口函数主要与统计类函数、排名类函数以及涉及行间计算的函数结合使用。
例如:
select t.*,
(t.score-avg(t.score) over( partition by t.subject_id)) as gaps
from test_student_score t
select t.*, rank() over(order by t.score desc) as ranks
from test_student_score t
where t.subject_id = 3;
排序函数ROW_NUMBER、RANK、DENSE_RANK
全部评论 (0)
还没有任何评论哟~
