排名问题

newqq 2010-02-07 05:06:51
需求如下:
A B C
1 3 9

2 1 6

5 7 2

想要得到得到

A 排名 B 排名 C 排名

1 1 3 2 9 3

2 2 1 1 6 2

5 3 7 3 2 1


谢谢:)
...全文
73 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
newqq 2010-02-07
  • 打赏
  • 举报
回复

A B C
SZTY 0.00 1
W0006 0.2295 12
W0004 0.2311 15
SZTY 0.00 1
W0004 0.3309 19
W0006 0.3314 22
W0006 0.40 25
SZTY 0.745 28
W0004 0.30 18
能不能得到
SZTY 0.00 1
W0006 0.2295 2
W0004 0.2311 3

SZTY 0.00 1
W0004 0.3309 2
W0006 0.3314 3

W0006 0.40 2
SZTY 0.745 3
W0004 0.30 1
newqq 2010-02-07
  • 打赏
  • 举报
回复
还有点问题
SZTY 0.00 1
W0006 0.2295 12
W0004 0.2311 15
SZTY 0.00 1
W0004 0.3309 19
W0006 0.3314 22
W0006 0.40 25
SZTY 0.745 28
W0004 0.30 18
排名排出来成这样了
newqq 2010-02-07
  • 打赏
  • 举报
回复
谢谢,真是高手,立马结贴
百年树人 2010-02-07
  • 打赏
  • 举报
回复
if object_id('[tb]') is not null drop table [tb]
go
create table [tb]([A] int,[B] int,[C] int)
insert [tb]
select 1,3,9 union all
select 2,1,6 union all
select 5,7,2
go

select
a,
a排名=(select count(1)+1 from tb where a<t.a),
b,
b排名=(select count(1)+1 from tb where b<t.b),
c,
c排名=(select count(1)+1 from tb where c<t.c)
from
tb t


--测试结果:
/*
a a排名 b b排名 c c排名
----------- ----------- ----------- ----------- ----------- -----------
1 1 3 2 9 3
2 2 1 1 6 2
5 3 7 3 2 1

(所影响的行数为 3 行)


*/
newqq 2010-02-07
  • 打赏
  • 举报
回复
我试试,谢谢
百年树人 2010-02-07
  • 打赏
  • 举报
回复
select 
a,
a排名=(select count(1)+1 from tb where a<t.a),
b,
b排名=(select count(1)+1 from tb where b<t.b),
c,
c排名=(select count(1)+1 from tb where c<t.c)
from
tb t
newqq 2010-02-07
  • 打赏
  • 举报
回复
貌似大家都没有上班

22,210

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧