[英]Add a new column with aggregate query into an existing table in mysql
這兩個表是:
學生 (student_id,student_name);
得分 (student_id,科目,得分1,得分2)。
我想在學生表格中添加新列,以查找每個學生所有學科的平均分數。 我怎樣才能做到這一點?
在學生表中添加您的分數列,然后您可以使用平均分數更新學生表,例如
UPDATE
student s
JOIN
(SELECT
student_id,
AVG(score1 + score2) score
FROM
score
GROUP BY student_id) sc
ON s.`student_id` = sc.student_id
SET s.`score` = sc.score
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.