sql server 对成绩的排序

懒懒羊 2012-08-10 05:46:38
把一个班的成绩分为A、B、C三个等级前十名为A,后十名为C,中间为B
求指教~~~
...全文
127 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhang19920408 2012-08-11
  • 打赏
  • 举报
回复
借用了下1L的代码,做了一些补充
with temp as
(
select ID, 成绩,名次=ROW_NUMBER()OVER(PARTITION BY 成绩 ORDER BY 成绩 desc)
FROM 表格
)
declare @count int
select @count=count(1) from 表格
select ID, 成绩, 等级 = (case when 名次 between 1 and 10 then 'A'
when 名次 between @count-9 and @count then 'C'
else 'B')
from temp

这样应该是LZ想要的
quchen520 2012-08-10
  • 打赏
  • 举报
回复
--A table
select top 10 * from tb
order by record

--B table
select * from tb
where
id not in(select top 10 id from tb
order by record )
and id not in(
select top 10 id from tb
order by record desc
)
--C table
select top 10 * from tb
order by record desc
shoppo0505 2012-08-10
  • 打赏
  • 举报
回复
大致如下:

with temp as
(
select ID, 成绩,名次=ROW_NUMBER()OVER(PARTITION BY 成绩 ORDER BY 成绩 desc)
FROM 表格
)
select ID, 成绩, 等级 = (case when 名次 between 1 and 10 then 'A'
else 'B')
from temp

22,210

社区成员

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

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