Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ms-access/4.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,使用Group By的查询是否可以显示空行 假设我的表有[PlaceID]和[Times] PlaceID I Times --------I------- 1 I 2 3 I 1 1 I 1 3 I 2 3 I 4 1 I 2 如果生成以下SQL,[PlaceID]将不可见,因为没有数据 SELECT PlaceID, Sum(Times) As SumTimes FROM tblOrder GR

使用Group By的查询是否可以显示空行

假设我的表有[PlaceID]和[Times]

PlaceID I Times
--------I-------
1       I   2
3       I   1
1       I   1
3       I   2
3       I   4
1       I   2
如果生成以下SQL,[PlaceID]将不可见,因为没有数据

SELECT PlaceID, Sum(Times) As SumTimes
FROM tblOrder
GROUP BY PlaceID;


PlaceID I SumTimes
--------I-------
1       I   5
3       I   7
是否可以强制它并获得此输出

PlaceID I SumTimes
--------I-------
1       I   5
2       I   0
3       I   7

你需要一个地方的列表。我猜是在
位置
表中

然后:


如果有三个以上的位置,您可以在(1、2、3)中添加
其中p.placeId

您是正确的,有带placeId和Place的tblPlace。并且有三个以上。由于用户可以添加位置,因此sql必须查看所有的PlaceID
select p.placeId, nz(sum(times), 0)
from places as p left join
     tblOrder as o
     on p.placeId = o.placeId
group by p.placeId;