2

我有一张桌子,看起来像:

在此处输入图像描述

罢工率基本上可以计算出 OrdersTaken - OrdersFrom,但我不想显示这两列,所以我只想要代码 + 罢工率调用

但是当我禁用显示时,它会提示我要求输入它的数字,所以它不再能够找到它了?

在此处输入图像描述

我的查询类似于:

SELECT T_Temp_RestrictedDiaryCalls.AccreditedDomainCode,
    Count(T_Temp_RestrictedProductSalesHistory.CustomerCode)
        AS OrdersTaken, qry_TargetReports.CountOfCustomerCode 
        AS OrdersFrom, [OrdersTaken]-[OrdersFrom] 
        AS [Strike Rate (Calls)]

    FROM qry_TargetReports 
        INNER JOIN (T_Temp_RestrictedDiaryCalls
        INNER JOIN T_Temp_RestrictedProductSalesHistory 
            ON (T_Temp_RestrictedDiaryCalls.CallDate = T_Temp_RestrictedProductSalesHistory.EntryDate)
                AND (T_Temp_RestrictedDiaryCalls.CustomerCode = T_Temp_RestrictedProductSalesHistory.CustomerCode)) 
            ON qry_TargetReports.AccreditedDomainCode = T_Temp_RestrictedDiaryCalls.AccreditedDomainCode

    GROUP BY T_Temp_RestrictedDiaryCalls.AccreditedDomainCode, qry_TargetReports.CountOfCustomerCode;

但老实说,MsAccess 为我生成了它。我只需要一种方法来隐藏两列,同时仍然计算总和,干杯。

4

2 回答 2

1

使用您现在拥有的所有内容,除了[OrdersTaken]-[OrdersFrom]作为子查询并计算父查询中的差异。

问题在于[OrdersTaken]和都是字段表达式的别名,而原始查询在计算 时试图在子句[OrdersFrom]中使用这些别名。通常 Access 不会让您这样做。SELECT[Strike Rate (Calls)]

SELECT
    sub.AccreditedDomainCode,
    (sub.OrdersTaken - sub.OrdersFrom) AS [Strike Rate (Calls)]
FROM
    (
        SELECT
            rdc.AccreditedDomainCode,
            Count(rpsh.CustomerCode) AS OrdersTaken,
            tr.CountOfCustomerCode AS OrdersFrom
        FROM
            qry_TargetReports AS tr
            INNER JOIN (T_Temp_RestrictedDiaryCalls AS rdc
            INNER JOIN T_Temp_RestrictedProductSalesHistory AS rpsh
            ON
                    (rdc.CallDate = rpsh.EntryDate)
                AND (rdc.CustomerCode = rpsh.CustomerCode)) 
            ON tr.AccreditedDomainCode = rdc.AccreditedDomainCode
        GROUP BY rdc.AccreditedDomainCode, tr.CountOfCustomerCode
    ) AS sub;
于 2013-11-05T14:14:08.153 回答
0

查看 SELECT :有 4 个部分对应于 4 个结果列

T_Temp_RestrictedDiaryCalls.AccreditedDomainCode,
Count(T_Temp_RestrictedProductSalesHistory.CustomerCode) AS OrdersTaken,
qry_TargetReports.CountOfCustomerCode AS OrdersFrom
[OrdersTaken]-[OrdersFrom] AS [Strike Rate (Calls)]

如果您只想要第 1 和第 4 行,只需删除第 2 和第 3 行:

T_Temp_RestrictedDiaryCalls.AccreditedDomainCode,
[OrdersTaken]-[OrdersFrom] AS [Strike Rate (Calls)]

但是,您还必须将 OrdersTaken 和 OrdersFrom 替换为它们的定义:

T_Temp_RestrictedDiaryCalls.AccreditedDomainCode,
Count(T_Temp_RestrictedProductSalesHistory.CustomerCode) # this is what OrdersTaken stands for
    - qry_TargetReports.CountOfCustomerCode # this is what OrdersFrom stands for
AS [Strike Rate (Calls)]

请注意,您还可以设置

Strike Rate (Calls):Count(T_Temp_RestrictedProductSalesHistory.CustomerCode)-qry_TargetReports.CountOfCustomerCode

在编辑器的查询定义中,这将执行相同的操作。

于 2013-11-05T14:16:46.940 回答