我有两个结果表,一个中期结果表和一个年度结果表。
中期结果表:
年度成绩表:
我想加入他们并找到每个学生每个科目的总分
求出期中成绩和期末成绩总分后的想要结果表
到目前为止我的代码:
mysql_query("drop view if exists result_view");
mysql_query("create view result_view as
select * from mid_term
UNION ALL
select * from annual") or die(mysql_error());
//now find the total marks of students for each subject
mysql_query("select id,student_id,subject_id,result_id,year,sum(mark) as mark
from result_view ");
但这不起作用,请提供任何帮助或建议!!!!!!1
最佳答案
我认为 id 字段在结果中没有多大意义,所以我省略了它。
SELECT Student_id,
Subject_id,
Result_id,
year,
SUM(mark)
FROM result_view
GROUP BY Student_id,
Subject_id,
Result_id,
year
关于mysql - 连接两个表并计算每个学生的分数总和,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19829210/