求一条SQL语句

wwoo_1105 2008-03-09 07:19:19
有下列表存在
表名:student
共有四列:STUDENT_ID STUDENT_NAME DEGREE
要求查询此表中成绩排名第六位的学生资料
...全文
84 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
flyidealism 2008-03-10
  • 打赏
  • 举报
回复
create table student(studentId int,studentName varchar(20),degree int)
insert into student
select 1,'张三',80
union all
select 2,'李四',85
union all
select 3,'王二',64
union all
select 4,'刘强',67
union all
select 5,'胡为',72
union all
select 6,'钟杨',93
union all
select 7,'罗文',76
union all
select 8,'张彬',86
union all
select 9,'王云',88


select top 1 * from
(
select top 6 *
from student
order by degree )T
order by degree desc

结果为:
2 李四 85




$扫地僧$ 2008-03-09
  • 打赏
  • 举报
回复

select top 1 *
from(select top 6 * from student order by DEGREE DESC) T
order by DEGREE
Limpire 2008-03-09
  • 打赏
  • 举报
回复
select * from student a where (select count(DEGREE) from student where DEGREE>a.DEGREE) = 5
piaoqifeng 2008-03-09
  • 打赏
  • 举报
回复
没装数据库,没验证语句。呵呵
piaoqifeng 2008-03-09
  • 打赏
  • 举报
回复

select * from student
where STUDENT_ID In
(
select top 1 STUDENT_ID from
(select top 6 * from student
order by 成绩 DESC) t
order by 成绩 ASC
)

34,591

社区成员

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

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