学习笔记:
学生选课数据库SCT
学生表(学号,姓名,性别,年龄,院系编号,班级)
Student(S# char(8),Sname char(10),Ssex char(2),Sage integer,D# char(2),Sclass char(6)
院系表(院系编号,院系名称,院长)
Dept(D# char(2),Dname char(10),Dean char(10))
课程表(课程编号,课程名称,课时,学分,授课老师编号)
Course(C# char(3),Cname char(12),Chours integer,Ccredit float(1),T# char(3))
教师表(老师编号,姓名,所属院系编号,工资)
Teacher(T# char(3),Tname char(10),D# char(2),Salary float(2))
选课表(学生学号,课程编号,成绩)
SC(S# char(8),C# char(3),Score float(1))
多表联合查询
1、按“001”号课程由高到低显示所有学生的姓名(二表链接)
select Sname from Student,SC where Student.S#=SC.S# and SC.C#=”001” order by Score desc;
2、按“数据库”课成绩由高到低顺序显示所有同学姓名(三表链接)
select Sname from Student,Course,SC where Student.S#=SC.S# and SC.C#=Course.C# and Cname=”数据库” order by Score desc;
3、求有薪水差额的任意两位教师
select T1.Tname as Teacher1,T2.Tname as T2 from Teacher T1,Teacher T2 where T1.Salary>T2.Salary;
4、求既学过“001”号课又学过“002”号课的所有学生的学号
select S1.S# from SC S1,SC S2 where S1.S#=S2.S# and S1.C#=”001”and S2.C#=”002”;