我已经创建了以下内容,但它不断出现错误消息您尝试执行的查询不包含指定的表达式' ICE Team'作为集合函数的一部分。
SELECT ztSub.[Master Sheet].[ICE Team], ztSub.[date], Count(ztSub.[Count])
FROM (SELECT [Master Sheet].[ICE Team],[Master Sheet].[Visit Date (planned for)] AS [date],Count([Master Sheet]![Visit Date (planned for)]) AS [Count]
FROM [Master Sheet]
UNION
SELECT [Master Sheet].[ICE Team],[Master Sheet].[Date retasked to?] AS [date], Count ([Master Sheet]![Date retasked to?]) AS [Count]
FROM [Master Sheet] ) AS ztSub
GROUP BY ztSub.[Master Sheet].[ICE Team];
答案 0 :(得分:1)
这现在有效。我收录了[日期的计数]和我给我的结果。
SELECT [Total].[Ice Team] AS [Ice Team], ztSub.Period, Sum(ztSub.[Count of Dates]) AS [SumOfCount of Dates]
FROM (SELECT Total.[Ice Team], Total.[Re-Visited] AS Period, Count([Total]![Re-Visited]) AS [Count of Dates]
FROM Total
GROUP BY [Ice Team], [Re-Visited]
UNION SELECT Total.[Ice Team], Total.Visited AS Period, Count([Total]![Visited]) AS [Count of Dates]
FROM Total
GROUP BY [Ice Team], Visited) AS ztSub
GROUP BY [Total].[Ice Team], ztSub.Period;
答案 1 :(得分:0)
如果您要查找的唯一结果是日期列表和出现次数,您可能想尝试使用联合查询:
SELECT date, count(*)
FROM (
(SELECT date_col1 AS date
FROM table1)
UNION
(SELECT date_col2 AS date
FROM table1) )
GROUP BY date
编辑更新的问题:
您的错误来自于您在内部查询中执行计数但在外部查询中执行分组的事实。如果你分别查看一个内部查询:
SELECT [Master Sheet].[ICE Team],[Master Sheet].[Visit Date (planned for)] AS [date],Count([Master Sheet]![Visit Date (planned for)]) AS [Count]
FROM [Master Sheet]
然后我们仍然得到同样的错误。这是因为您在select子句中计算了日期,而没有指定如何处理[ICE Team]值。您可能希望为[ICE Team]值包含group by子句。您已经为外部查询做了,但它也应该在这个内部查询中完成。您的Visit Date (planned for)
值也是如此,否则您将获得相同的错误。
尝试此查询,但我不确定它是否也会根据您的需要提供结果。 (为此,您必须为您的问题添加输入和预期输出的明确示例。)
SELECT ztSub.[Master Sheet].[ICE Team], ztSub.[date], Count(ztSub.[Count])
FROM (SELECT [Master Sheet].[ICE Team],[Master Sheet].[Visit Date (planned for)] AS [date],Count([Master Sheet]![Visit Date (planned for)]) AS [Count]
FROM [Master Sheet]
group by [ICE Team],[Visit Date (planned for)]
UNION
SELECT [Master Sheet].[ICE Team],[Master Sheet].[Date retasked to?] AS [date], Count ([Master Sheet]![Date retasked to?]) AS [Count]
FROM [Master Sheet]
group by [ICE Team], [Date retasked to?] ) AS ztSub
GROUP BY ztSub.[Master Sheet].[ICE Team],date;