我有以下代码,目的是统计每个组中在给定时间范围内离开公司的员工人数。我正在使用 COUNT IIF,它说代码的每一位中 AND 之后的 <= 符号是错误的。我应该如何计算日期范围?
SELECT O867IA_VPJOBCO.JOB_GRP_CD, Count(IIf(O867IA_VJOBHST.REC_EFF_STT_DT>=#1/1/2009# And <= #12/31/2009#,2009,0)) AS 2009, Count(IIf(O867IA_VJOBHST.REC_EFF_STT_DT>=#1/1/2010# And <= #12/31/2010#,2010,0)) AS 2010, COUNT(IIF(O867IA_VJOBHST.REC_EFF_STT_DT >= #1/1/2011# AND <= #12/31/2011#, 2011, 0)) AS 2010, COUNT(IIF(O867IA_VJOBHST.REC_EFF_STT_DT >= #1/1/2012# AND <= #12/31/2012#, 2012, 0)) AS 2012,
FROM (O867IA_VJOBHST INNER JOIN O867IA_VACTRSN ON (O867IA_VJOBHST.EMP_ACN_RSN_TYP_CD = O867IA_VACTRSN.EMP_ACN_RSN_TYP_CD) AND (O867IA_VJOBHST.EMP_ACN_TYP_CD = O867IA_VACTRSN.EMP_ACN_TYP_CD)) INNER JOIN O867IA_VPJOBCO ON O867IA_VJOBHST.JOB_CLS_CD = O867IA_VPJOBCO.JOB_CLS_CD
WHERE (((O867IA_VJOBHST.REC_EFF_STT_DT)>=#1/1/2009# And (O867IA_VJOBHST.REC_EFF_STT_DT)<=#12/31/2012#) AND ((O867IA_VACTRSN.EMP_ACN_TYP_CD)<>"RMT"))
GROUP BY O867IA_VPJOBCO.JOB_GRP_CD
HAVING (((O867IA_VPJOBCO.JOB_GRP_CD)>='72' And (O867IA_VPJOBCO.JOB_GRP_CD)<='94'));