Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql MS ACCESS中使用自联接的多列之和_Sql_Ms Access - Fatal编程技术网

Sql MS ACCESS中使用自联接的多列之和

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

我有一张表——表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

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

非常感谢你!看来我想得太多了!非常感谢你!看来我想得太多了!