I need to add totals per month, as well as a total amount for all months.
how can i amend this select to add totals.
your help will be highly appreciated
how can i amend this select to add totals.
Code:
WITH t1 AS
(SELECT CASE
WHEN mm = '01'
THEN tot
ELSE 0
END AS jan, CASE
WHEN mm = '02'
THEN tot
ELSE 0
END AS feb, CASE
WHEN mm = '03'
THEN tot
ELSE 0
END AS mar, CASE
WHEN mm = '04'
THEN tot
ELSE 0
END AS apr, CASE
WHEN mm = '05'
THEN tot
ELSE 0
END AS may, CASE
WHEN mm = '06'
THEN tot
ELSE 0
END AS jun, CASE
WHEN mm = '07'
THEN tot
ELSE 0
END AS jul, CASE
WHEN mm = '08'
THEN tot
ELSE 0
END AS aug, CASE
WHEN mm = '09'
THEN tot
ELSE 0
END AS sep, CASE
WHEN mm = '10'
THEN tot
ELSE 0
END AS oct, CASE
WHEN mm = '11'
THEN tot
ELSE 0
END AS nov, CASE
WHEN mm = '12'
THEN tot
ELSE 0
END AS DEC, CASE
WHEN mm IS NULL
THEN tot
ELSE 0
END AS total
FROM (SELECT TO_CHAR (CREATION_DATE, 'MM') mm, COUNT (1) AS tot
FROM applsys.fnd_user
WHERE creation_date > to_date('01-01-2010','DD-MM-YYYY')
GROUP BY ROLLUP (TO_CHAR (CREATION_DATE, 'MM'))
ORDER BY 1) a),
t2 AS
(SELECT SUM (jan) jan, SUM (feb) feb, SUM (mar) mar, SUM (apr) apr,
SUM (may) may, SUM (jun) jun, SUM (jul) jul, SUM (aug) aug,
SUM (sep) sep, SUM (oct) oct, SUM (nov) nov, SUM (DEC) DEC,
SUM (total) AS total
FROM t1)
SELECT *
FROM t1
UNION ALL
SELECT *
FROM t2
your help will be highly appreciated