sql 难句

cjhyahoo 2003-05-24 09:50:23
表中有sno(学生号),cno(课程号),grade(成绩)
求:1
找出考了学号为001的学生的全部课程的学生
2,
满足1,且每门成绩都比他高的学生
...全文
23 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
pengdali 2003-05-24
  • 打赏
  • 举报
回复
1、
select * from 表 where sno in (select sno from 表 where sno<>'001' and cno in (select cno from 表 where sno='001') group by sno having sum(1)>=(select sum(1) from 表 where sno='001'))

或:

select sno from 表 where sno<>'001' and cno in (select cno from 表 where sno='001') group by sno having sum(1)>=(select sum(1) from 表 where sno='001')


2、
select * from 表 where sno in (select sno from 表 tem where sno<>'001' and exists (select 1 from 表 where sno='001' and cno=tem.cno and grade<tem.grade) group by sno having sum(1)>=(select sum(1) from 表 where sno='001'))

或:

select sno from 表 tem where sno<>'001' and exists (select 1 from 表 where sno='001' and cno=tem.cno and grade<tem.grade) group by sno having sum(1)>=(select sum(1) from 表 where sno='001')
samuelpan 2003-05-24
  • 打赏
  • 举报
回复
1、select * from table where cno in(select cno from table where sno='001')
and sno in(select sno from table group by sno having count(*)>
(select count(*) from table where sno='001'))

2、select a.* from table a,
(select * from table where sno='001') t
where a.cno=t.cno and a.grade>t.grade and sno in(select sno from table group by sno having count(*)>(select count(*) from table where sno='001'))
order by sno,cno
erigido 2003-05-24
  • 打赏
  • 举报
回复
学习

34,575

社区成员

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

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