使用字母等级计算GPA-SQL

时间:2018-12-03 00:01:52

标签: sql

<div class="stats">
  <p>Online Users: 100</p>
  <p id="queue">Players in Queue: 1</p>
</div>

有人可以帮助我吗?我到处搜寻!我要回答的问题是:对于他/她参加的所有课程,学生的累积成绩点是多少。

1 个答案:

答案 0 :(得分:0)

您应该单独按学生进行汇总,然后取CASE表达式的加权平均值:

SELECT
    S.FirstName,
    S.LastName,
    SUM(CreditHours *
        CASE Grade WHEN 'A' Then 4
                   WHEN 'B' Then 3
                   WHEN 'C' Then 2
                   WHEN 'D' Then 1
                   WHEN 'F' Then 0 END) / SUM(CreditHours) AS GradePoint
FROM Student s
INNER JOIN Enrollment e
    ON s.StudentID = e.StudentID
INNER JOIN Course c
    ON e.CourseID = c.CourseID 
GROUP BY
    s.FirstName,
    s.LastName;