一条sql语句

Laughing 2008-07-19 09:09:09
关系为:
STUDENT
学号 姓名 年龄 性别 系号
SC
学号 课程号 成绩
COURSE
课程号 课程名 学时数

请用SQL语言检索至少选修了与学号是“S3”的学生选修的全部课程相同的学生的学号和姓名。
...全文
120 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
zbc1009 2008-07-19
  • 打赏
  • 举报
回复
标准老是布置的作业题目,楼上们有不少正确答案~
wwwtyb 2008-07-19
  • 打赏
  • 举报
回复
select 学号,姓名 from stuent
where 学号=(select sc_a.学号 from sc as sc_a,sc as sc_b
where sc_a.课程号=sc_b.课程号 and sc_b.学号='s3')

dawugui 2008-07-19
  • 打赏
  • 举报
回复
[Quote=引用楼主 aqszhuaihuai 的帖子:]
关系为:
STUDENT
学号 姓名 年龄 性别 系号
SC
学号 课程号 成绩
COURSE
课程号 课程名 学时数

请用SQL语言检索至少选修了与学号是“S3”的学生选修的全部课程相同的学生的学号和姓名。
[/Quote]
--如果排除重复关系,可以这样:

select 学号 ,姓名 from student where sc in (select sc from sc group by sc having count(*) + (select count(*) from sc where 学号 = 'S3'))
mulpig 2008-07-19
  • 打赏
  • 举报
回复
select 1 from Sc

这是啥意思啊?
ChinaJiaBing 2008-07-19
  • 打赏
  • 举报
回复

select student.学号,姓名 from student inner join sc
on student.学号=sc.学号 where 课程号 in
(select s.课程号 from sc s inner join course c
on s.课程号= c.课程号
where s.学号 = 's3')
wzy_love_sly 2008-07-19
  • 打赏
  • 举报
回复
select * from student 
where 学号 in(
select a.学号 from
(select * from sc where 学号<>'s3') a
join (select * from sc where 学号='s3') b
on a.课程号=b.课程号 group by a.学号
having count(1)=(select count(1) from sc where 学号='s3'))


dsp_zerg 2008-07-19
  • 打赏
  • 举报
回复
不知道对不对

select 学号,姓名 from stuent
where 学号=(select 学号 from sc
where 课程号=(select 课程号 from sc where 学号='s3'))
中国风 2008-07-19
  • 打赏
  • 举报
回复
写多一种方法,或用in方法

select
*
from
STUDENT a
where
not exists(select 1 from sc b left join sc c on b.课程号=c.课程号 and c.学号=a.学号 where b.学号='S3' and c.课程号 is null)
中国风 2008-07-19
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 BernardSun 的回复:]
楼上多了个from,好像是很经典的考题哦
[/Quote]

随手敲的

select
*
from
STUDENT a
where
not exists(
select * from sc b where 学号='S3' and not exists(select 1 from Sc where 学号=a.学号 and 课程号=b.课程号))
qqhmitzk 2008-07-19
  • 打赏
  • 举报
回复
select
学号 姓名
from
STUDENT a
where
not exists(
select * from sc b where 学号='S3' and b.课程号 not in(select 课程号 from Sc where 学号=a.学号 and 课程号=b.课程号))
qqhmitzk 2008-07-19
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 roy_88 的回复:]
SQL code select
学号 姓名
from
STUDENT a
where
not exists(
select * from sc b where 学号='S3' and not exists(select 1 from Sc where 学号=a.学号 and 课程号=b.课程号))
[/Quote]
BernardSun 2008-07-19
  • 打赏
  • 举报
回复
楼上多了个from,好像是很经典的考题哦
中国风 2008-07-19
  • 打赏
  • 举报
回复
select 
*
from
STUDENT a
from
where
not exists(
select * from sc b where 学号='S3' and not exists(select 1 from Sc where 学号=a.学号 and 课程号=b.课程号))
ws_hgo 2008-07-19
  • 打赏
  • 举报
回复
又是这个题目啊!
我这是第4次看见拉!~

34,588

社区成员

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

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