我为所有内容提供了正确的数字,但是当我尝试使用ORDER BY
子句时,它可以工作,但平均GPA行排在数据的顶部。应该在最后。
我尝试了ISNULL
,GROUPING
,但它们都没有起作用。
SELECT se.sectionid AS sectionid, st.lname AS last_name, st.fname AS first_name, g.letter AS letter, FORMAT(AVG(gs.point),2) AS gpa
FROM student as st, section as se, grade as g, grade_scale as gs
WHERE st.studentid = g.studentid AND se.sectionid = g.sectionid AND g.letter = gs.letter AND se.sectionid = 35
GROUP BY sectionid, last_name, first_name, letter
UNION
SELECT 'Average GPA','', '','', FORMAT(AVG(gs.point),2) AS gpa
FROM student as st, section as se, grade as g, grade_scale as gs
WHERE st.studentid = g.studentid AND se.sectionid = g.sectionid AND g.letter = gs.letter AND se.sectionid = 35
ORDER BY last_name, first_name;
“平均GPA”行应位于底部,我在Google上搜索的任何内容均无效。该表应按last_name和first_name排序。
谢谢!