谁能帮我解一下SQL语句呢?谢谢各位啦!

来源:百度知道 编辑:UC知道 时间:2024/05/08 08:22:12
题目: A. 对于教学数据库存的三个基本表:
S(S#,SNAME,AGE,SEX)
SC(S#,C#,GRADE)
C(C#,CNAME,TEACHER)
试用SQL的查询语句表达下列查询:
1.检索LIU老师所授课程的课程号和课程号.
2.检索年龄大于23岁的男学生的学号和姓名.
3.检索学号为S3学生所学课程的课程名与任课教师名.
4.检索至少选修LIU老师所授课程中一门课程的女学生姓名.
5.检索WANG同学不学的课程的课程号.
6.检索至少选修两门课程的学生学号.
7.检索全部学生都选修的课程的课程号与课程名.
8.检索选修课程包含LIU老师所授课程的学生学号.

1.select c#,cname from c where teacher='liu'
2.select s#,sname from s where age>23 and sex='男'
3.select cname,teacher from sc,c where sc.c#=c.c# and s#='s3'
4.select distinct sname from s,sc,c where s.s#=sc.s# and c.c#=sc.c# and teacher='liu'
5.select c# from c where not in (select c# from sc where s#=(select s# from s where sname='wang'))
6.select s# from s,sc where s.s#=sc.s# group by s# having count(c#)>=2
7.select c#,cname from c where c# in (select c# from sc as sc1 where sc1.s# not in (select s.s# from sc as sc2 ,s where not exists (select * from s ,sc as sc3 where sc3.c#=sc2.c# and sc3.s#=s.s#)))
8.Select s# from sc sc1 where c# in
(select c# from sc as sc2 where not exists (select * from c where teacher='liu' and not exists( select * from sc as sc3 where sc3.s#=sc2.s# and sc3.c#=c.c#)))