1、多表连接查询
(1) 查询选修了【数据库原理】的计算机系的学生学号和姓名。
select students.sno,sname,cname from students,courses,sc
where
students.sno = sc.sno and courses.cno=sc.cno and cname='数据库原理' and sdept='计算机'
(2) 查询每一门课的间接先行课(即先行课的先行课),显示课程编号和该门课程的间接先行课编号。
select c1.cno,c2.precno
from courses c1 left join courses c2
ON c1.precno=c2.cno
where c2.precno is not null
(3) 查询学生的学号、姓名、选修课程的名称和成绩。
select students.sno,sname,cname,grade
from students,sc,courses
where students.sno=sc.sno and sc.cno=courses.cno
(4) 查询选修了课程的学生姓名。
select sname
from students
where sno in (select sno from sc);
(5) 查询所有学生的信息和所选修的课程, 要求显示学生的学号、姓名、课程号及课程名。没有选课的同学对应的选课信息为空。
select DISTINCT students.sno,students.sname,sc.cno,cname
from students
left join sc on stud