计算平均成绩点

时间:2014-07-02 12:12:51

标签: mysql sql

这个示例代码她只是计算出表3的平均成绩,而不是真正的GPA:SELECT *    FROM(    选择AVG(g.Grade)作为average_grade,g.SSN    从等级g    g.SSN小组)a    内部联接学生在a.ssn = s.ssn;

找出正确的公式:这是我想出的但是不正确     选择 *    FROM(    SELECT SUM(Grade * CreditHour)/(SUM(CreditHour)as average_grade,g.SSN    从等级g    g.SSN小组)a    内部联接学生在a.ssn = s.ssn;

Need some help stuck on this problem?

1 个答案:

答案 0 :(得分:1)

在我看来,好像你只是忘了加入课程表的成绩表。或者我错过了什么?

SELECT * 
FROM 
( 
  SELECT 
    SUM(g.Grade*c.CreditHour) / SUM(c.CreditHour) as average_grade, 
    g.SSN 
  FROM Grade g
  INNER JOIN Course c ON c.cno = g.cno                         
  GROUP BY g.SSN
) a 
INNER JOIN Student s ON a.ssn = s.ssn;