我正在使用MS Access(北风数据库),当我尝试运行底部查询时,出现以下错误。
您的查询不包括指定的expexpion'单价* 数量”作为聚合函数的一部分。
我无法弄清楚自己在做什么:
Select productid, unitprice * quantity AS total_price, count (orderid) as total_count
FROM [order details]
GROUP BY productid, price
答案 0 :(得分:1)
您可以简单地执行此操作。在group by语句中,您只能包括分组列以及Sum,Count等。这些被称为“聚合函数”。
不是聚合函数(或位置或表达式)的任何列都需要在分组依据中列出。
我认为您希望这样做:
Select productid, Count (orderid) as total_count, Sum (unitprice * quantity) AS total_price
FROM [order details]
GROUP BY productid