SQL Server 查询数据排名情况SQL
这篇文章主要为大家详细介绍了SQL Server 查询数据排名情况SQL,具有一定的参考价值,可以用来参考一下。
对此感兴趣的朋友,看看idc笔记做的技术笔记!
1/准备测试数据
---------------------------------------------------------------------------------create table t1(c1 integer,c2 integer,c3 integer);
insert into t1 values(1,2,3)
insert into t1 values(1,8,4)insert into t1 values(1,4,4)
insert into t1 values(1,4,5)
insert into t1 values(1,5,5)
insert into t1 values(2,2,3)
insert into t1 values(2,8,4)insert into t1 values(2,4,4)
insert into t1 values(2,4,5)
insert into t1 values(2,5,5)
2/查看排名
---------------------------------------------------------------------------------
A/单记录排名
select c1,c3,(select count( c3)+1 from t1 a where a.c3>b.c3and a.c1=b.c1 and a.c1 =1) order_numfrom t1 bwhere c1 =1order by c1,c3
c1 c3 order_num----------- ----------- ----------------------1 3 51 4 31 4 31 5 11 5 1B/多记录排名
select c1,c2,c3,(select count( c3)+1 from t1 a where a.c3>b.c3and a.c1=b.c1) order_numfrom t1 border by c1,c3
c1 c2 c3 order_num----------- ----------- ----------- ----------------------1 2 3 51 8 4 31 4 4 31 4 5 11 5 5 12 2 3 52 8 4 32 4 4 32 4 5 12 5 5 1
注:关于SQL Server 查询数据排名情况SQL的内容就先介绍到这里,更多相关文章的可以留意