我正在尝试列出教过 Java 课程最多的讲师所讲授的 Java 课程的讲师。
首先我选择教Java课程的讲师
SELECT z.FIRST_NAME,z.LAST_NAME,b.COURSE_NO, MAX(b.DESCRIPTION) AS DESCRIPTION
FROM INSTRUCTOR z
JOIN SECTION w ON z.INSTRUCTOR_ID = w.INSTRUCTOR_ID
JOIN COURSE b ON w.COURSE_NO = b.COURSE_NO
WHERE DESCRIPTION like '%Java%'
GROUP BY z.FIRST_NAME,z.LAST_NAME,b.COURSE_NO
它显示了到目前为止我想要的结果
FIRST_NAME LAST_NAME COURSE_NO DESCRIPTION
------------------------- ------------------------- ---------- ---------------------------------
Tom Wojick 120 Intro to Java Programming
Gary Pertez 120 Intro to Java Programming
Anita Morris 124 Advanced Java Programming
Todd Smythe 122 Intermediate Java Programming
Charles Lowry 122 Intermediate Java Programming
Charles Lowry 120 Intro to Java Programming
Fernand Hanks 122 Intermediate Java Programming
etc...
但是当我尝试选择教授 Java 课程最多的讲师时,我得到了完全不同的结果
SELECT z.FIRST_NAME,z.LAST_NAME,b.COURSE_NO,b.DESCRIPTION
FROM INSTRUCTOR z
JOIN SECTION w ON z.INSTRUCTOR_ID = w.INSTRUCTOR_ID
JOIN COURSE b ON w.COURSE_NO = b.COURSE_NO
WHERE DESCRIPTION like '%Java%'
GROUP BY z.FIRST_NAME,z.LAST_NAME,b.COURSE_NO,b.DESCRIPTION
HAVING MAX(b.DESCRIPTION) =
(SELECT MAX(DESCRIPTION)
FROM (
SELECT z.FIRST_NAME,z.LAST_NAME,b.COURSE_NO, MAX(b.DESCRIPTION) AS DESCRIPTION
FROM INSTRUCTOR z
JOIN SECTION w ON z.INSTRUCTOR_ID = w.INSTRUCTOR_ID
JOIN COURSE b ON w.COURSE_NO = b.COURSE_NO
WHERE DESCRIPTION like '%Java%'
GROUP BY z.FIRST_NAME,z.LAST_NAME,b.COURSE_NO
)
)
ORDER BY z.FIRST_NAME,z.LAST_NAME,b.COURSE_NO,b.DESCRIPTION;
我如何计算这些描述 Java 课程并从中选择最大值,以便它只能显示一位讲师的所有 Java 课程?