asked on
****************************************************************************
1rst EXAMPLE:
**************************************
SELECT DeptName, sum(ThisMonthRec) AS ReceivedThisMonth, sum(RollingAvg) AS RollingAverage, sum(YearToDatTtl) AS YearToDateRec
FROM
(SELECT
request_dept_nm AS DeptName,
Count(request_dept_nm) AS ThisMonthRec,
NULL AS RollingAvg,
NULL AS YearToDatTtl
FROM request_fact
WHERE requested_dt BETWEEN Forms!frmRSS_TtlsByFrq!cmbMonthBeg AND Forms!frmRSS_TtlsByFrq!cmbMonthEnd
GROUP BY request_dept_nm
UNION ALL
SELECT
request_dept_nm AS DeptName,
NULL AS ThisMonthRec,
Round((Count(request_dept_nm))/12) As RollingAvg,
NULL AS YearToDatTtl
FROM request_fact
WHERE requested_dt BETWEEN DateDiff("m", -12, Forms!frmRSS_TtlsByFrq!cmbMonthEnd) AND Forms!frmRSS_TtlsByFrq!cmbMonthEnd
GROUP BY request_dept_nm)
GROUP BY DeptName;
****************************************************************************
2nd EXAMPLE:
**************************************
SELECT DeptName, sum(ThisMonthRec) AS ReceivedThisMonth, sum(RollingAvg) AS RollingAverage, sum(YearToDatTtl) AS YearToDateRec
FROM
(SELECT
request_dept_nm AS DeptName,
Count(request_dept_nm) AS ThisMonthRec,
NULL AS RollingAvg,
NULL AS YearToDatTtl
FROM request_fact
WHERE requested_dt BETWEEN Forms!frmRSS_TtlsByFrq!cmbMonthBeg AND Forms!frmRSS_TtlsByFrq!cmbMonthEnd
GROUP BY request_dept_nm
UNION ALL
SELECT
request_dept_nm AS DeptName,
NULL AS ThisMonthRec,
Round((Count(request_dept_nm))/12) As RollingAvg,
NULL AS YearToDatTtl
FROM request_fact
WHERE requested_dt BETWEEN DateDiff("m", -12, Forms!frmRSS_TtlsByFrq!cmbMonthEnd) AND Forms!frmRSS_TtlsByFrq!cmbMonthEnd
GROUP BY request_dept_nm
UNION ALL
SELECT
request_dept_nm AS DeptName,
NULL AS ThisMonthRec,
NULL As RollingAvg,
Count(request_dept_nm) As YearToDatTtl
FROM request_fact
WHERE requested_dt BETWEEN #06/01/2008# AND #06/30/2008#
GROUP BY request_dept_nm)
GROUP BY DeptName;