4. 使用标准SQL嵌套语句查询选修全部课程的学员姓名和所属单位
SELECT SN,SD FROM S
WHERE [S#] IN(
SELECT [S#] FROM SC
RIGHT JOIN C ON SC.[C#]=C.[C#]
GROUP BY [S#]
HAVING COUNT(*)=COUNT(DISTINCT [S#]))
后面的HAVING COUNT(*)=COUNT(DISTINCT [S#]))看不明白啊....
------解决方案--------------------
HAVING COUNT(*)=COUNT(DISTINCT [S#])是对结果集进行限制,只让选修科目数和总科目数相等的出现在结果集中
其中的COUNT(DISTINCT [S#])就是查出科目总数的,由于有distinct所以科目不重复出现,自然就是总科目数了