数据库的一个问题

来源:百度知道 编辑:UC知道 时间:2024/06/28 13:00:34
设有如下关系模式:
学生:STUDENT(SNO,SNAME,AGE,CITY)
教师:TEACHER(TNO,TNAME,TITLE,AGE)
课程:COURSE(CNO,CNAME,TNUM)
联系关系:STC(SNO,TNO,CNO)
其中,TITLE为该教师的职称,TNUM为该课程的任课教师数.
一个学生可以选修多门课程,一门课程可由多位老师讲授.
请用SQL语句完成下列操作:
(1)查找职称为教授的教师的全部数据.
(2)查找给学生"刘芳"上"操作系统"课程的教师姓名.

上面两位明显是错的
子查询里面的字段都不一样,你查个屁啊

第一题没问题
select * from teacher where title='教授';

第二题
select tname from teacher as a,student as b,course as c,stc as d

where a.tno=d.tno
and b.sno =d.sno
and c.cno=d.cno
and b.sanme='刘芳'
and c.cname='操作系统'

如果是用子查询做
select tname from teacher where tno in (select tno from stc where sno in (select sno from student where sname='刘芳')and cno in(select cno from course where cname='操作系统'))

(1) select * from teacher where title='教授';
(2) select tname from teacher where tno in
(select sno from student,course where sno = cno and sname = '刘芳' and cname = '操作系统');

(1)select * from teacher where title='教授';

(2)select tname from teacher where tno in
(select stc.tno from stc,course,student where stc.sno=student.sno and stc.cno=course.cno and course='操作系统