[英]SUM of multiple columns using SELF JOIN in MS ACCESS
我有一張桌子 - table1 如下所示:
+------+--------+--------+-----+
ID---hours1---hours2-----hours3--+
1-------4-------3---------2----+
2-------8-------7---------6----+
1-------5-------2---------1----+
2-------10------11--------2----+
預期成績:
ID-----Total
1--------17
2--------44
我嘗試了如下 SELF 連接查詢:
SELECT ID, SUM(hours1 + hours2 + hours3)
from table1 a inner join table1 b ON a.Id = b.Id
group by a.Id
然而,這給出了不正確的結果,結果非常奇怪。 誰能幫我上面的查詢有什么問題?
我認為不需要自我加入,只是:
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.