我想根据成绩和学分计算每个学生的 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 查询的结果有很多行。所以我没能完成这个。我的桌子是这样的:
我正在使用 PostgreSQL。
试试这个:
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