我正在尝试获取期末考试成绩高于平均水平的学生名单
我首先选择平均
SELECT w.LAST_NAME , AVG(s.NUMERIC_GRADE) AS NUMERIC_GRADE
GRADE s , SECTION z, STUDENT w
WHERE s.SECTION_ID = z.SECTION_ID AND s.STUDENT_ID = w.STUDENT_ID
AND s.SECTION_ID = 90 AND s.GRADE_TYPE_CODE = 'FI'
GROUP BY w.LAST_NAME,s.NUMERIC_GRADE
我得到这四个结果
LAST_NAME NUMERIC_GRADE
------------------------- -------------
Mulroy 83
Da Silva 92
Lopez 91
Abid 84
但是当我尝试从这四个中获得上述平均值时,我没有得到任何行,并且看起来子查询和主查询具有相同的条件。我不确定如何在平均之后执行上述操作。
SELECT n.LAST_NAME , m.NUMERIC_GRADE
FROM GRADE m , STUDENT n
WHERE m.STUDENT_ID = n.STUDENT_ID
GROUP BY n.LAST_NAME , m.NUMERIC_GRADE
HAVING COUNT(*) >
(SELECT AVG (NUMERIC_GRADE)
FROM
(SELECT w.LAST_NAME , AVG(s.NUMERIC_GRADE) AS NUMERIC_GRADE
FROM GRADE s , SECTION z, STUDENT w
WHERE s.SECTION_ID = z.SECTION_ID AND s.STUDENT_ID = w.STUDENT_ID
AND s.SECTION_ID = 90 AND s.GRADE_TYPE_CODE = 'FI'
GROUP BY w.LAST_NAME,s.NUMERIC_GRADE))
ORDER BY n.LAST_NAME;
我想得到 numberic_grade 91 和 92,因为它高于平均水平。当我试图选择那些在期末考试中高于平均水平的人时,为什么它没有给我任何行?