您的位置:首页 > 数据库

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

2011-09-08 13:04 274 查看
在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

*/

这样就可以啦
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: