在Access中,我有两个表,并且我被要求将这些表中的一些统计信息输出到查询结果中。麻烦的是,我不知道该怎么做,或者即使它是可能的。
我正在寻找的输出如下 -
我需要查询的表格是这样构成的 -
表1 - Active Directory -
表2 - IBM Notes -
我知道如何加入表格并输出位置和计数字段,但我很好,真的输了。任何提示和技巧都表示赞赏。
这是我到目前为止所拥有的 -
SELECT DISTINCT [Active Directory].[AD Location] AS [Location], Count([Active Directory].[AD Location]) AS [Count]
FROM [Active Directory] INNER JOIN [IBM Notes] ON [AD Active Directory].[AD Email Address] = [IBM Notes].[Notes Email Address];
这里有一些来自Active Directory和IBM Notes表的示例数据,以及预期的结果(每个都在它自己的选项卡上) -
答案 0 :(得分:2)
这样的事情 - 我想你明白了。我在你的问题中看到邮箱大小不是一个数字,所以你必须将它转换为数字千兆字节。您必须进行此更改才能使其发挥作用。
SELECT
A.[AD Location] AS [Location],
Count(A.[AD Location]) AS [Count],
SUM(Val(N.[Notes Mailbox Size])) AS [Total Mailbox Size],
AVG(Val(N.[Notes Mailbox Size])) AS [Average Mailbox Size],
SUM(IIF(Val(N.[Notes Mailbox Size]) > 1.5,1,0)) AS [Large Mailboxes]
FROM [Active Directory] AS A
INNER JOIN [IBM Notes] AS N ON A.[AD Email Address] = N.[Notes Email Address]
GROUP BY A.[AD Location]
以上语句包括检查以确保Notes Mailbox Size
字段中的值不是Null
-
SELECT
A.[AD Location] AS Location,
Count(A.[AD Location]) AS [Count of Location],
Sum(IIf(IsNull(N.[Notes Mailbox Size]), "0", Val(N.[Notes Mailbox Size]))) AS [Total Mailbox Size (GB)],
Round(Avg(IIf(IsNull(N.[Notes Mailbox Size]), "0", Val(N.[Notes Mailbox Size]))), 2) AS [Average Mailbox Size (GB)],
Sum(IIf(IsNull(N.[Notes Mailbox Size]), "0", IIf(Val(N.[Notes Mailbox Size]) > 2.5, 1, 0))) AS [Count of Large Mailboxs]
FROM [Active Directory] AS A
INNER JOIN [IBM Notes] AS N ON A.[AD Email Address] = N.[Notes Email Address]
GROUP BY A.[AD Location];