一个比较难的查询语句

alex_82712 2007-07-23 06:02:28
题目:请按照学习成绩的大小,输出名次在10-20之间的学生的信息
表结构:id(primary key),stu_Name,stu_Score
尽量在一个表里,如不行,也可以分开

请各位指点!
谢谢
...全文
233 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
suxujie 2007-07-25
  • 打赏
  • 举报
回复
小泛滥,快给分
suxujie 2007-07-25
  • 打赏
  • 举报
回复
select top 10 * from TblName where stu_Score >(select max(stu_Score) from (select top 10 stu_Score from TblName order by stu_Score desc)as tblTmp) order by stu_Score
y51704545 2007-07-24
  • 打赏
  • 举报
回复
冒泡~
pastbee 2007-07-23
  • 打赏
  • 举报
回复
xueguang(xg) 说的很好
willman0982 2007-07-23
  • 打赏
  • 举报
回复
SELECT B.Id, B.Stu_Name, B.Stu_Score
FROM
(SELECT A.*, ROW_NUMBER() OVER(ORDER BY StuScore DESC) AS RowId FROM StudentScore A) AS B
WHERE B.RowId BETWEEN 10 AND 20
xueguang 2007-07-23
  • 打赏
  • 举报
回复
SELECT TOP 10 * FROM TEST WHERE id not in(SELECT TOP 10 id FROM TEST ORDER BY stu_Score) ORDER BY stu_Score,id
suxujie 2007-07-23
  • 打赏
  • 举报
回复
小泛滥
昵称被占用了 2007-07-23
  • 打赏
  • 举报
回复
select *,(select count(*) from tablename where stu_Score>a.stu_Score or stu_Score=a.stu_Score and id<=a.id) as 名次 from tablename a
where (select count(*) from tablename where stu_Score>a.stu_Score or stu_Score=a.stu_Score and id<=a.id) between 10 and 20
昵称被占用了 2007-07-23
  • 打赏
  • 举报
回复
select * from tablename a
where (select count(*) from tablename where stu_Score>a.stu_Score or stu_Score=a.stu_Score and id<=a.id) between 10 and 20

34,593

社区成员

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

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