Home > Database > Mysql Tutorial > oracle之dense

oracle之dense

WBOY
Release: 2016-06-07 15:25:55
Original
1235 people have browsed it

1.over over()不能单独使用,一般都是和其他函数一起使用。 函数名( [ 参数 ] ) over( [ 分区子句 ] [ 排序子句 [ 滑动窗口子句 ] ]) 比如rank(score) over(partition by clazz order by score desc);按班级分组partition by clazz相当于group by clazz

      1.over

      over()不能单独使用,一般都是和其他函数一起使用。

     函数名( [ 参数 ] ) over( [ 分区子句 ]  [ 排序子句 [ 滑动窗口子句 ] ])

        比如rank(score) over(partition by clazz order by score desc);按班级分组partition by clazz相当于group by clazz,相同班级里面按成绩由高到低排名。


     下面建立测试表来测试over()的一些用法.

      oracle之dense

     成绩排名,不区分班级

select s.name 姓名,s.clazz 班级,s.score 成绩,
rank() over( order by score desc ) 名次 --名次不连续
from student s
Copy after login
oracle之dense
    仔细查看,发现如果遇到有同分的,名次就不连续了。如果需要名次连续的,则可使用dense_rank();

select s.name 姓名,s.clazz 班级,s.score 成绩,
dense_rank() over( order by score desc ) 名次 --名次连续
from student s
Copy after login
oracle之dense

    over()还可以和其他函数组合使用,比如sum()、avg()等

select s.name 姓名,s.clazz 班级,s.score 成绩,
rank() over(partition by s.clazz order by score desc ) 名次,
avg(s.score) over(partition by s.clazz) 平均分,
sum(s.score) over(partition by s.clazz ) 班级总分,
sum(s.score) over(partition by s.clazz order by s.score desc ) 累计--此功能多是用于统计某时间段内每天累计的收入
from student s order by 平均分 desc,名次 asc ;
Copy after login
oracle之dense

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template