--------------------------表結構--------------------------
student(StuId,StuName,StuAge,StuSex) 學生表
teacher(TId,Tname) 教師表
course(CId,Cname,C_TId) 課程表
sc(SId,S_CId,Score) 成績表
----------------------------------------------------------
問題十四:查詢和“1002”號的同學學習的課程完全相同的其他同學學號和姓名
SELECT StuId,StuName FROM student WHERE StuId= ANY( SELECT SId FROM sc WHERE SId NOT IN (SELECT SId FROM sc WHERE S_CId NOT IN (SELECT S_CId FROM sc WHERE SId='1002')) GROUP BY SId HAVING COUNT(*)= (SELECT COUNT(*) FROM sc WHERE SId='1002') ) AND StuId<>'1002';
答案僅供參考,不一定完全正確,若發現錯誤或有更好的,歡迎評論,互相交流,一起成長!!!