仅在分区的最后一行显示值

时间:2015-09-10 12:29:52

标签: sql database window-functions

我正在为数据库中的学生生成成绩单。我正在使用窗口函数来提供运行学期和累积GPA。我的查询如下:

SELECT FIRSTNAME, COURSENAME, SCORE, MAX_SCORE, SEMESTER, SGPA, AVG(ROUND(SGPA,2)) OVER (PARTITION BY FIRSTNAME ORDER BY SEMESTER) AS CGPA

FROM(

SELECT FIRSTNAME, COURSENAME, SCORE, MAX_SCORE, SEMESTER, ROUND((SEM_TOTAL_SCORE * 4/SEM_TOTAL_MAX_SCORE ),2) AS SGPA FROM(

SELECT FIRSTNAME, COURSENAME, SCORE, MAX_SCORE, SEMESTER,
SUM(SCORE)
OVER (PARTITION BY FIRSTNAME ORDER BY SEMESTER) AS SEM_TOTAL_SCORE,
SUM(MAX_SCORE)
OVER (PARTITION BY FIRSTNAME ORDER BY SEMESTER) AS SEM_TOTAL_MAX_SCORE
FROM STUDENT_GRADE_COURSE
)
);

我得到以下结果:

enter image description here

现在结果是正确的。但我不想在每一行上显示SGPA和CGPA。相反,我希望它们只显示在分区的最后一行,在本例中是分区。因此,在第一学期和第二学期的最后一行,我看到gpas ...在其他行上,这些列中不应显示任何内容。

我该怎么做?

0 个答案:

没有答案