OVER 轻松搞定排名查询

不多说,上代码,可以根据需要,分年级,科目,及性别出排名

 

drop table #t1;
create table #t1 select年级 varchar select50,科目 varchar select50,学生名 varchar select20,性别 varchar select2,分数 decimal select18,2

insert into #t1 select '一年级','语文','akuoma1','男',90.5
insert into #t1 select '一年级','语文','akuoma2','男',90.5
insert into #t1 select '一年级','语文','akuoma3','男',91.5
insert into #t1 select '一年级','数学','akuoma1','男',90.5
insert into #t1 select '一年级','数学','akuoma2','男',92.5
insert into #t1 select '一年级','数学','akuoma3','男',93.5
insert into #t1 select '一年级','美术','akuoma1','男',91.5
insert into #t1 select '一年级','美术','akuoma2','男',90.5
insert into #t1 select '一年级','美术','akuoma3','男',90.5
insert into #t1 select '一年级','英语','akuoma1','男',90.5
insert into #t1 select '一年级','英语','akuoma2','男',92.5
insert into #t1 select '一年级','英语','akuoma3','男',94.5

insert into #t1 select '一年级','语文','lisa1','女',91.5
insert into #t1 select '一年级','语文','lisa2','女',92.5
insert into #t1 select '一年级','语文','lisa3','女',91.5
insert into #t1 select '一年级','数学','lisa1','女',93.5
insert into #t1 select '一年级','数学','lisa2','女',94.5
insert into #t1 select '一年级','数学','lisa3','女',95.5
insert into #t1 select '一年级','美术','lisa1','女',95.5
insert into #t1 select '一年级','美术','lisa2','女',96.5
insert into #t1 select '一年级','美术','lisa3','女',97.5
insert into #t1 select '一年级','英语','lisa1','女',99.5
insert into #t1 select '一年级','英语','lisa2','女',98.5
insert into #t1 select '一年级','英语','lisa3','女',93.5

insert into #t1 select '二年级','语文','akuoma1','男',90.5
insert into #t1 select '二年级','语文','akuoma2','男',90.5
insert into #t1 select '二年级','语文','akuoma3','男',91.5
insert into #t1 select '二年级','数学','akuoma1','男',90.5
insert into #t1 select '二年级','数学','akuoma2','男',92.5
insert into #t1 select '二年级','数学','akuoma3','男',93.5
insert into #t1 select '二年级','美术','akuoma1','男',91.5
insert into #t1 select '二年级','美术','akuoma2','男',90.5
insert into #t1 select '二年级','美术','akuoma3','男',90.5
insert into #t1 select '二年级','英语','akuoma1','男',90.5
insert into #t1 select '二年级','英语','akuoma2','男',92.5
insert into #t1 select '二年级','英语','akuoma3','男',94.5

insert into #t1 select '二年级','语文','lisa1','女',91.5
insert into #t1 select '二年级','语文','lisa2','女',92.5
insert into #t1 select '二年级','语文','lisa3','女',91.5
insert into #t1 select '二年级','数学','lisa1','女',93.5
insert into #t1 select '二年级','数学','lisa2','女',94.5
insert into #t1 select '二年级','数学','lisa3','女',95.5
insert into #t1 select '二年级','美术','lisa1','女',95.5
insert into #t1 select '二年级','美术','lisa2','女',96.5
insert into #t1 select '二年级','美术','lisa3','女',97.5
insert into #t1 select '二年级','英语','lisa1','女',99.5
insert into #t1 select '二年级','英语','lisa2','女',98.5
insert into #t1 select '二年级','英语','lisa3','女',93.5

select DENSE_RANK() over( partition by 年级,科目 order by 年级,科目,分数 Desc) as 排名,t.*
from #t1 t where 年级='一年级'


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值