6. SQL开窗函数
- 聚合函数是在分组后将多行聚合成一行
- 开窗函数是在不分组的情况下,得到一个新字段,这个新字段根据多行数据计算得出
示例一
计算每个学生各科成绩在其总分的占比:
select sno as '学号',
sum(score) over(partition by sno) as sum_score,
score / sum_score *100 as '占比'
from xxx
Loading...
计算每个学生各科成绩在其总分的占比:
select sno as '学号',
sum(score) over(partition by sno) as sum_score,
score / sum_score *100 as '占比'
from xxx