我的 select 语句中有嵌套IIF()
函数,每个函数内部都有一个嵌套的MAX()
. 似乎希望我将这个 select 语句包含在 GROUP BY 中。这是我的查询:
SELECT
d2s_loader_performance_tbl.employee_id,
IIF(d2s_loader_performance_tbl.wk_ending_dt=max(d2s_loader_performance_tbl.wk_ending_dt),"Last Wk",
IIF(d2s_loader_performance_tbl.wk_ending_dt=max(d2s_loader_performance_tbl.wk_ending_dt)-7,"2 Wks Ago",
IIF(d2s_loader_performance_tbl.wk_ending_dt=max(d2s_loader_performance_tbl.wk_ending_dt)-14,"3 Wks Ago",
IIF(d2s_loader_performance_tbl.wk_ending_dt=max(d2s_loader_performance_tbl.wk_ending_dt)-21,"4 Wks Ago")))),
d2s_loader_performance_tbl.hrs_worked,
d2s_loader_performance_tbl.move_count,
d2s_loader_performance_tbl.moves_per_hour
FROM d2s_loader_performance_tbl
WHERE d2s_loader_performance_tbl.wk_ending_dt In (
SELECT DISTINCT TOP 4 wk_ending_dt
FROM d2s_loader_performance_tbl
ORDER BY wk_ending_dt DESC)
GROUP BY
d2s_loader_performance_tbl.employee_id,
d2s_loader_performance_tbl.move_count,
d2s_loader_performance_tbl.moves_per_hour
当我运行时,我收到此错误:“您尝试执行一个不包含指定表达式的查询 [列出作为嵌套 IIF 的块] 作为聚合函数的一部分。当我将它放在 GROUP BY 中时(没有意义),我收到此错误:“不能在 GROUP BY 子句中具有聚合函数”
那么,访问希望我在 HE-double 曲棍球棒中做什么?这样做的目的是将周末日期变成一个相对术语。该报告每周更新一次,我厌倦了手动浏览所有查询和报告并将引用更改为新日期。
谢谢!