在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
*/
这样就可以啦
--建立测试环境
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
*/
这样就可以啦
相关文章推荐
- SQL实现分组排序和组内排序(相同分数并列排名)
- 在select中添加排名列的SQL语句
- 增加排名列SQL语句(需排名的列值相等时排名相同)
- 增加排名列SQL语句(需排名的列值相等时排名相同)
- SQL Server 创建表 添加主键 添加列常用SQL语句
- access数据库用sql语句添加字段,修改字段,删除字段
- access数据库用sql语句添加字段,修改字段,删除字段
- 用sql语句添加删除主键
- mybatis生产的sql语句,添加的时候报如下异常,不知道怎么回事
- Union All拼接Sql语句做批量添加
- 使用sql语句添加约束
- sql 语句为表添加列设定默认值
- SQL_添加语句
- 使用sql语句创建表、修改表、添加列等
- SQL语句查询结果额外添加一列序号自动增加
- 在几千条记录里,存在着些相同的记录,如何能用SQL语句,删除掉重复
- 查询表里面有N组相同的记录经典SQL语句
- 给数据库字段添加注释,并且可以通过sql语句查询
- 一周乱弹(0624 1,maven 添加依赖包.2,sqlserver 删除语句.3..OutOfMemoryError: PermGen space。4,SQL datediff (时间差)
- 使用sql语句创建表、修改表、添加列等