<p> ①检索年龄小于17岁的女学生的学号和姓名。<br> SELECT S#.SNAME FROM S<br> WHERE AGE<17 AND SEX=’F’<br> ②检索男学生所学课程的课程号和课程名。<br> SELECT C.C#,CNAME (连接查询方式) FROM S,SC,C<br> WHERE S.S#=SC.S# AND SC.C#=C.C# AND SEX=’M’;<br> ③检索男学生所学课程的任课老师的工号和姓名。<br> SELECT T.T#, TNAME FROM S,SC,C,T<br> WHERE S.S#=SC.S# AND SC.C#=C.C# AND C.T#=T.T# AND SEX=’M’;<br> ④检索至少选修两门课程的学生学号。<br> SELECT DISTINCT X.S# FROM SC AS X, SC AS Y<br> WHERE X.S#=Y.S# AND X.C#!=Y.C#;<br> ⑤检索至少有学号为S2和S4的学生选修的课程的课程号。<br> SELECT DISTINCT X.C# FROM SC AS X, SC AS Y<br> WHERE X.S#=’S2’ AND Y.S#=’S4’ AND X.C#=Y.C#;<br> ⑥检索WANG同学不学的课程的课程号。<br> SELECT C# FROM C<br> WHERE NOT EXISTS (SELECT * FROM S, SC<br> WHERE S.S#=SC.S# AND SC.C#=C.C# AND SNAME=’WANG’);<br> ⑦检索全部学生都选修的课程的课程号与课程名。<br> SELECT C#,CNAME FROM C<br> WHERE NOT EXISTS (SELECT * FROM S<br> WHERE NOT EXISTS (SELECT * FROM SC<br> WHERE S#=S.S# AND C#=C.C#));<br> ⑧检索选修课程包含LIU老师所授全部课程的学生学号。<br> 法一:<br> SELECT DISTINCT S# FROM SC AS X<br> WHERE NOT EXISTS (SELECT * FROM C,T<br> WHERE C.T#=T.T# AND TNAME=’LIU’<br> AND NOT EXISTS (SELECT{<br> FROM SC AS Y<br> WHERE Y.S#=X.S# AND Y.C#=C.C#));<br> 法二:<br> SELECT DISTINCT S# FROM SC X<br> WHERE NOT EXISTS ((SELECT C# FROM C,T<br> WHERE C.T#=T.T# AND TNAME='LIU’) EXCEPT<br> (SELECT C# FROM SC Y WHERE Y.S#=X.S#));</p>