Access Query +您的查询不包含指定表达式'TimeID'作为聚合函数的一部分

时间:2013-11-27 19:58:04

标签: sql ms-access insert

当我尝试运行查询时,我收到以下错误

您的查询不包含指定表达式'TimeID'作为聚合函数

的一部分
INSERT INTO dwSalesFacts ( FactID, TimeID, CustomerID, EmployeeID, LocationID, ProductID, Quantity, UnitPrice, Discount )
SELECT COUNT(FactID), dwTime.TimeID, Orders.[Customer ID], Orders.[Employee ID], dwLocation.LocationID, [Order Details].[Product ID], [Order Details].Quantity, [Order Details].[Unit Price], [Order Details].Discount
FROM Orders, dwTime, dwLocation, [Order Details];

1 个答案:

答案 0 :(得分:1)

由于您的COUNT(FactID)声明中有SELECT,因此您需要指定GROUP BY,如下所示:

GROUP BY dwTime.TimeID, Orders.[Customer ID], 
  Orders.[Employee ID], dwLocation.LocationID, 
  [Order Details].[Product ID], [Order Details].Quantity, 
  [Order Details].[Unit Price], [Order Details].Discount

这是否是你想要的计数分组我不知道,但根据你的选择,它是必须的。

如果FactID是自动编号字段,那么您甚至不需要指定它。请尝试以下方法:

INSERT INTO dwSalesFacts (TimeID, CustomerID, EmployeeID, LocationID, 
    ProductID, Quantity, UnitPrice, Discount)
SELECT t.TimeID, o.[Customer ID], o.[Employee ID], l.LocationID, 
    od.[Product ID], od.Quantity, od.[Unit Price], od.Discount
FROM Orders AS o, dwTime AS t, dwLocation AS l, [Order Details] AS od