0
我想列出在第三次測驗中收到低於平均成績的學生。低於AVG子查詢不顯示正確的結果
首先我選擇
SELECT s.STUDENT_ID, s.LAST_NAME,g.GRADE_TYPE_CODE,AVG (g.NUMERIC_GRADE) AS GRADE
FROM STUDENT s, GRADE g
WHERE s.STUDENT_ID = g.STUDENT_ID
AND g.SECTION_ID = 135 AND g.GRADE_TYPE_CODE= 'QZ' AND g.GRADE_CODE_OCCURRENCE = 3
GROUP BY s.STUDENT_ID, s.LAST_NAME,g.GRADE_TYPE_CODE
和我收到的平均四個結果
STUDENT_ID LAST_NAME GRADE
---------- ------------------------- ----------
178 Kurtz 98
215 Chatman 90
259 Merriman 81
214 Williams 99
但是當我要選擇那些誰接受低於平均水平,我得到165行中選擇
SELECT z.STUDENT_ID, z.LAST_NAME
FROM STUDENT z, GRADE w
WHERE z.STUDENT_ID = w.STUDENT_ID
GROUP BY z.STUDENT_ID, z.LAST_NAME
HAVING COUNT(*) <
(SELECT AVG(GRADE)
FROM
(SELECT s.STUDENT_ID, s.LAST_NAME,g.GRADE_TYPE_CODE,AVG (g.NUMERIC_GRADE) AS GRADE
FROM STUDENT s, GRADE g
WHERE s.STUDENT_ID = g.STUDENT_ID
AND g.SECTION_ID = 135 AND g.GRADE_TYPE_CODE= 'QZ' AND g.GRADE_CODE_OCCURRENCE = 3
GROUP BY s.STUDENT_ID, s.LAST_NAME,g.GRADE_TYPE_CODE))
ORDER BY z.LAST_NAME;
我在做什麼錯,我如何列出收到低於平均成績的學生?