我有一张表格,上面写着所有的学生都必须上10门课,其中5门是必修课,另外5门是必修课,所以基本上有两个小组。现在我需要计算总学分和团体学分的总和。
表1
StudentID ProgID ProgName GroupID GroupName Course Complete_Courses_Alert Credits
1 100 MS 501 Mandatory 12 Remaining 3
1 100 MS 501 Mandatory 13 Complete 3
1 100 MS 501 Mandatory 14 Complete 3
1 100 MS 501 Mandatory 15 Remaining 3
1 100 MS 501 Mandatory 16 Complete 3
1 100 MS 502 Elective 17 Complete 3
1 100 MS 502 Elective 18 Complete 3
1 100 MS 502 Elective 19 Remaining 3
1 100 MS 502 Elective 20 Complete 3
1 100 MS 502 Elective 21 Remaining 3我想要输出
上表,但有两个字段更多地添加到它。
即已完成学分之和(总学分)和完整学分之和(按组分列)
这就是我到目前为止所做的工作,我创建了一个计算总学分和GrouptotalCredits的视图,然后在主查询中加入它。这样,我再次需要创建另一个视图来执行查询上的更多功能。
有人能帮上忙吗。
发布于 2013-07-15 16:43:35
我想你是在找这样的东西:
select *
, StudentGroupCredits = sum(case when Complete_Courses_Alert = 'Complete' then Credits else 0 end) over (partition by StudentId, GroupName)
, StudentTotalCredits = sum(case when Complete_Courses_Alert = 'Complete' then Credits else 0 end) over (partition by StudentId)
from Courses与演示。
有关更多信息,请查看联机丛书上的关于条款。
https://stackoverflow.com/questions/17658986
复制相似问题