SQL-vsvswhere我有以下两张表:1. Lecturers (LectID, Fname, Lname, degree).2. Lecturers_Specialization (LectID, Expertise).我想找一个专业程度最高的讲师。当我尝试这个时,它是不起作用的:SELECT
L.LectID,
Fname,
Lname
FROM Lecturers L,
Lecturers_Specialization SWHERE L.LectID = S.LectIDAND COUNT(S.Expertise) >= ALL (SELECT
COUNT(Expertise)FROM Lecturers_SpecializationGROUP BY LectID);但当我尝试这个时,它起作用了:SELECT
L.LectID,
Fname,
Lname
FROM Lecturers L,
Lecturers_Specialization SWHERE L.LectID = S.LectIDGROUP BY L.LectID,
Fname,
Lname
HAVING COUNT(S.Expertise) >= ALL (SELECT
COUNT(Expertise)FROM Lecturers_SpecializationGROUP BY LectID);原因是什么?谢谢。
3 回答
ITMISS
TA贡献1871条经验 获得超8个赞
WHERE
HAVING
HAVING
WHERE
GROUP BY
HAVING
GROUP BY
SELECT L.LectID, Fname, LnameFROM Lecturers LJOIN Lecturers_Specialization S ON L.LectID=S.LectIDGROUP BY L.LectID, Fname, LnameHAVING COUNT(S.Expertise)>=ALL(SELECT COUNT(Expertise) FROM Lecturers_Specialization GROUP BY LectID)
WHERE
慕慕森
TA贡献1856条经验 获得超17个赞
“WHERE子句与WHERE子句相同,但适用于分组记录”。
添加回答
举报
0/150
提交
取消