如何在microsoft access查询中将多个条目合并为一个新值?

jpfvwuh4  于 2021-08-13  发布在  Java
关注(0)|答案(1)|浏览(441)

我正在尝试为不同的[po类型]合计[award]和[counter]的总数。有没有一种方法可以将所有现有采购订单类型分组到同一查询中的一个值“srm”中?
我想要的最终结果是一张唱片:srm | 37823372.89 | 1732美元

以下是当前sql:

SELECT tblSRMECC.[PO Type], Sum(tblSRMECC.Award) AS SumOfAward, Count(tblSRMECC.[Counter (PO)]) AS 
[CountOfCounter (PO)]
FROM tblSRMECC
GROUP BY [PO Type]
HAVING (((tblSRMECC.[PO Type])<>"AutoPO" And (tblSRMECC.[PO Type])<>"Fixed Price Catalog"));
vcirk6k6

vcirk6k61#

一种方法是修改现有查询以添加 UNION 这就是小计。类似这样的sql:

SELECT 0 AS DataSortOrder, tblSRMECC.[PO Type], Sum(tblSRMECC.Award) AS SumOfAward, Count(tblSRMECC.[Counter (PO)]) AS 
[CountOfCounter (PO)]
FROM tblSRMECC
GROUP BY [PO Type]
HAVING (((tblSRMECC.[PO Type])<>"AutoPO" And (tblSRMECC.[PO Type])<>"Fixed Price Catalog"))
UNION SELECT 1,"SRM",Sum(tblSRMECC.Award), Count(tblSRMECC.[Counter (PO)]) 
FROM tblSRMECC
HAVING (((tblSRMECC.[PO Type])<>"AutoPO" And (tblSRMECC.[PO Type])<>"Fixed Price Catalog"))
ORDER BY 1,2

我添加的额外列datasortorder只是为了确保合计出现在各个合计之后。
如果您只想显示总体合计,那么您可以使用我添加的查询部分:

SELECT "SRM",Sum(tblSRMECC.Award), Count(tblSRMECC.[Counter (PO)]) 
FROM tblSRMECC
HAVING (((tblSRMECC.[PO Type])<>"AutoPO" And (tblSRMECC.[PO Type])<>"Fixed Price Catalog"))

当做,

相关问题