我有公立学校的成绩数据。我标准化数据库并创建了三个表,即标记表、学校表和学生表。我想编写查询以获得每所学校的通过。在这里,我粘贴了让学生总数出现在考试中的查询,以同样的方式我会得到通过的学生。
SELECT a.Year_id
, school_code
, count(a.Marks_id) AS TotalAppeared
FROM
Marks_Table a
JOIN Master_Student ms
ON ms.Student_id = a.Student_id
JOIN Master_School mss
ON mss.school_id = ms.School_code_int
WHERE
CANDIDATE_TYPE = 'RF'
AND TOTAL_MARKS != 0
AND school_code = 'AS0180'
AND a.Year_id BETWEEN 5 AND 9
GROUP BY
a.Year_id
, SCHOOL_CODE
如何优化此查询