sql??

yunxiang 2003-12-10 11:42:22
表:

学号 分数

1 50
2 56
3 87
4 40
5 23


查找结果:

学号 分数 名次
1 50 3
2 56 2
3 87 1
4 40 4
5 23 5

...全文
27 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
azsoft 2003-12-11
  • 打赏
  • 举报
回复
SELECT *,(select count(*)+1 from 表 B WHERE A.分数<B.分数) AS 名次 FROM 表 A ORDER BY A.学号
azsoft 2003-12-11
  • 打赏
  • 举报
回复
select a.学号,a.分数,b.名次 from 表 Inner join (select 分数,identity(int,1,1)as 名次 from 表 order by 分数 desc
) b on a.分数=b.分数
CrazyFor 2003-12-11
  • 打赏
  • 举报
回复

select *,(select count(*) from 表 bb where bb.分数<=aa.分数) as 名次 from 表 aa order by 学号
azsoft 2003-12-11
  • 打赏
  • 举报
回复
declare @t Table (学号 varchar(10),分数 varchar(10))
insert into @t
select '1','50'
union all select '2','56'
union all select '3','87'
union all select '4','40'
union all select '5','23'

select 学号,分数 into #t from @t
select 分数,identity(int,1,1)as 名次 into #t1 from @t order by 分数 desc

select #t.学号,#t.分数,#t1.名次 from #t left join #t1 on #t1.分数=#t.分数

drop Table #t
drop Table #t1
dlpseeyou 2003-12-11
  • 打赏
  • 举报
回复
select * ,名次=(select sum(1) from test2 b where a.分数<=b.分数)from test2 a order by 学号
victorycyz 2003-12-11
  • 打赏
  • 举报
回复
select * ,identity(int,1,1) into #t from table1 order by 分数 desc
select * from #t order by id
go

drop table #t

34,837

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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