如何根据成绩和学分计算GPA?

问题描述 投票:0回答:1

我想根据成绩和学分计算每个学生的 GPA。我已经执行过类似的事情

SET GPA=(SELECT((t.grade*c.credits)/c.credits)
FROM Student s, Take t, Courses c
WHERE s.sid=t.sid and t.cid=c.cid)

这不起作用。 Select 查询的结果有很多行。所以我没能完成这个。我的桌子是这样的:

  • 取(sid,cid,等级)
  • 课程(cid,学分)
  • 学生(sid,gpa)

我正在使用 PostgreSQL。

sql postgresql select group-by aggregate-functions
1个回答
0
投票

试试这个:

SELECT s.sid, (SUM(t.grade * c.credits) / SUM(t.credits)) AS GPA
FROM Student s
INNER JOIN Take t ON s.sid = t.sid 
INNER JOIN Courses c ON t.cid = c.cid
GROUP BY s.sid
© www.soinside.com 2019 - 2024. All rights reserved.