學習筆記:
學生選課數據庫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”;
新聞熱點
疑難解答