Sql MS ACCESS中使用自联接的多列之和
我有一张表——表1如下:Sql MS ACCESS中使用自联接的多列之和,sql,ms-access,Sql,Ms Access,我有一张表——表1如下: +------+--------+--------+-----+ ID---hours1---hours2-----hours3--+ 1-------4-------3---------2----+ 2-------8-------7---------6----+ 1-------5-------2---------1----+ 2-------10------11--------2----+ 预期成果: ID-----Total 1--------17
+------+--------+--------+-----+
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
我尝试了如下的自连接查询:
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
我认为这不需要自连接,只是:
select t.id, sum(t.hours1+t.hours2+t.hours3) as total
from table1 t
group by t.id
非常感谢你!看来我想得太多了!非常感谢你!看来我想得太多了!