我正在尝试在Access中运行以下代码:
SELECT T_SAP_IST.month, SUM(T_SAP_IST.value), IIf([description]="hours","hours","nonhours") AS descr
FROM T_SAP_IST
GROUP BY month, descr
我的目标是获得每个月的所有值的总和,分为“小时”和“非小时”。但是,我收到一条错误消息,指出“'IIf([description] =“ hours”,“ hours”,“ nonhours”)'不是聚合函数的一部分”
我该如何解决?感谢您的帮助!
在MS Access中,您需要重复表达:
SELECT T_SAP_IST.month, SUM(T_SAP_IST.value),
IIf([description]="hours","hours","nonhours") AS descr
FROM T_SAP_IST
GROUP BY month, IIf([description] = "hours", "hours", "nonhours");
您还可以使用子查询,因此不必重复该表达式。 MS Access在GROUP BY
中不支持列别名。