数据库SQL查询作业

 

--设有三个关系
--S(S#,SNAME,AGE,SEX)
--SC(S#,C#,GRADE)
--C(C#,CNAME,TEACHER)

--(1)检索LIU老师所授课程的课程号、课程名
select c#,cname from c
where teacher='LIU'
--(2)检索年龄大于23岁的男同学的学号和姓名
select s#,sname from s
where age>23 and sex='男'
--(3)检索学号为S3学生所学课程的课程名与任课教师名
select cname,teacher from c,sc
where c.c#=sc.c# and s#='s3'
--(4)检索至少选修LIU老师所授课程中一门课程的女学生的姓名
--1.嵌套查询
select sname from s
where sex='女' and s# in
(select s# from sc where c# in
(select c# from c where teacher='LIU'))
--2.多表联合查询
select sname from s,sc,c 
where s.s#=sc.s# and sc.c#=c.c# and teacher='LIU' and s.sex='女'
--(5)检索王同学不学的课程号
--1.
select c# from c where c# not in
(select c# from sc where s# in 
(select s# from s where sname='wang'))
--2.
select c# from sc where c# not in
(select c# from s,sc where s.s#=sc.s# and sname='wang') 
--(6)检索至少选修两门课程的学生学号
select distinct x.s# from sc x,sc y
where x.s#=y.s# and x.c#!=y.c#
--(7)检索全部学生都选修的课程的课程号与课程名
--1.
select c.c#,cname
from sc,c
where sc.c#=c.c#
group by c.c#,cname 
having COUNT(*)=(select COUNT(*)from s)
--2.
select c#,cname from c
where not exists
(select * from s
where s# not in
(select * from sc where sc.c#=c.c#));
--(8)检索选修课程包含LIU老师所授课程的学生学号
select distinct s# from sc
where c# in
(select c# from c
where teacher='liu');

 

全部评论

相关推荐

06-12 17:46
门头沟学院 Java
运营你豪哥:来说重点: ​1.项目前置,时间倒序。​​ 2.​项目描述强化结果与量化效果(STAR原则里的R)。​​ ​3.个人技能精炼,明确掌握程度,突出核心。​​ ​4.增加强有力开头的个人总结部分。​​ 5.​优化教育背景(成绩排名)、合并奖项与活动。​​
听劝,我这个简历该怎么改...
点赞 评论 收藏
分享
醉蟀:你不干有的是人干
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-11 11:21
被夸真的超级开心,好可爱的姐姐
码农索隆:老色批们不用脑补了,我把金智妮的图找来了查看图片
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务