根据表单中的某个字段分割表单并选取字段中的最大值

在一个表中根据某个字段的值来将表分割再选取其中的最大值。
比如各个班级中的成绩最高的一个如:
student sid classNum score
1 1 89
2 4 80
3 3 82
4 3 90
5 2 89
6 1 97
create table student{
int sid primary key,
int classnum ,
int score;
}
select sid,classnum,score
from (
select sid,classnum,score,row_number() over(partition by classnum order

by score desc)row_num from student
)
where row_num=1

现将sid,classnum,score 按classnum分割表单,然后再根据score排序降序,为每个分割的
子表单设定row_num:
6 1 97 1
1 1 89 2
5 2 89 1
4 3 90 1
3 3 82 2
2 4 80 1
然后选取row_num=1的字段也就是表中每个班级中成绩最大的值。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值