[英]SUM of multiple columns using SELF JOIN in MS ACCESS
I have a table - table1 like below:我有一张桌子 - table1 如下所示:
+------+--------+--------+-----+
ID---hours1---hours2-----hours3--+
1-------4-------3---------2----+
2-------8-------7---------6----+
1-------5-------2---------1----+
2-------10------11--------2----+
Expected Results:预期成绩:
ID-----Total
1--------17
2--------44
I tried SELF join query as below:我尝试了如下 SELF 连接查询:
SELECT ID, SUM(hours1 + hours2 + hours3)
from table1 a inner join table1 b ON a.Id = b.Id
group by a.Id
However this is giving incorrect results and results are very weird.然而,这给出了不正确的结果,结果非常奇怪。 Can anyone please help me what's wrong in above query?
谁能帮我上面的查询有什么问题?
I don't think the self-join is required for this, just:我认为不需要自我加入,只是:
select t.id, sum(t.hours1+t.hours2+t.hours3) as total
from table1 t
group by t.id
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.