有3个表S,C,SC
S(SNO,SNAME)代表(学号,姓名)
C(CNO,CNAME,CTEACHER)代表(课号,课名,教师)
SC(SNO,CNO,SCGRADE)代表(学号,课号,课号成绩)
问题:
1,找出没选过“黎明”老师的所有学生姓名。
2,列出2门以上(含2门)不及格学生姓名及平均成绩。
3,即学过1号课程有学过2号课所有学生的姓名。
请用标准SQL语言写出答案。
------解决方案--------------------------------------------------------
1.
select * from s,sc
where not exists (select 1 from c where 课号 = sc.课号 and 教师 = '黎明')
and s.学号 = sc.学号
2.
select s.学号,s.姓名,avg(成绩)
from s,sc
where s.学号 = sc.学号
and s.学号 in (
select 学号
from s,sc
where s.学号 = sc.学号
and 成绩<60
group by 学号
having count(1) > 1)
group by s.学号,s.姓名
3.
select sc.姓名
from s,sc a
where s.学号 = sc.学号 and 课号 = 1
and exists (select 1 from sc where 课号 = 2 and a.学号 = 学号)