在SQL语句中添加分数相同的项的相同排名

来源:互联网 发布:淘宝虚拟物品交易规则 编辑:程序博客网 时间:2024/06/05 18:02

在SQL语句中添加分数相同的项的相同排名

--建立测试环境
create   table   studentQK   (CG   float,     MC   int)
--插入数据
insert   into   studentQK
select   55, ' '       union   all            
select   65, ' '       union   all
select   88, ' '   union   all
select   88, ' '   union   all
select   88, ' '   union   all
select   66, ' '   union   all
select   66, ' '   union   all
select   90, ' '   union   all
select   99, ' '
--测试
Update   A   Set   MC=(Select   IsNull(Count(Distinct   CG),0)+1   from   studentQK   Where   CG> A.CG)   from   studentQK   A
Select   *   from   studentQK   Order   By   MC
--删除测试环境
Drop   table   studentQK
--结果
/*
CG MC
99.0 1
90.0 2
88.0 3
88.0 3
88.0 3
66.0 4
66.0 4
65.0 5
55.0 6
*/

 

这样就可以啦

 

原创粉丝点击