[英]ms access - query null row
Is it possible a query with Group By to show null rows? 使用分组依据查询是否可以显示空行?
let's say that my table has [PlaceID] and [Times]. 假设我的表格有[PlaceID]和[Times]。
PlaceID I Times
--------I-------
1 I 2
3 I 1
1 I 1
3 I 2
3 I 4
1 I 2
If I make the following SQL, [PlaceID] will not be visible because there is no data. 如果执行以下SQL,则[PlaceID]将不可见,因为没有数据。
SELECT PlaceID, Sum(Times) As SumTimes
FROM tblOrder
GROUP BY PlaceID;
PlaceID I SumTimes
--------I-------
1 I 5
3 I 7
Is it possible to force it and have this output 是否可以强制它并具有此输出
PlaceID I SumTimes
--------I-------
1 I 5
2 I 0
3 I 7
You need a list of places . 您需要一个地点清单。 .
。 .
。 which I would guess is in the
places
table. 我猜是在
places
表中。
Then: 然后:
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;
If there are more than three places, you can add where p.placeId in (1, 2, 3)
. 如果有三个以上的位置,则可以
where p.placeId in (1, 2, 3)
添加where p.placeId in (1, 2, 3)
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.