Code:
CREATE TABLE APPLSYS.FND_USER
(
USER_ID NUMBER(15),
USER_NAME VARCHAR2(100 BYTE),
LAST_UPDATE_DATE DATE,
LAST_UPDATED_BY NUMBER(15),
CREATION_DATE DATE,
CREATED_BY NUMBER(15),
LAST_UPDATE_LOGIN NUMBER(15),
ENCRYPTED_FOUNDATION_PASSWORD VARCHAR2(100 BYTE),
ENCRYPTED_USER_PASSWORD VARCHAR2(100 BYTE),
SESSION_NUMBER NUMBER,
START_DATE DATE,
END_DATE DATE,
DESCRIPTION VARCHAR2(240 BYTE),
LAST_LOGON_DATE DATE,
PASSWORD_DATE DATE,
PASSWORD_ACCESSES_LEFT NUMBER(15),
PASSWORD_LIFESPAN_ACCESSES NUMBER(15),
PASSWORD_LIFESPAN_DAYS NUMBER(15),
EMPLOYEE_ID NUMBER(15),
EMAIL_ADDRESS VARCHAR2(240 BYTE),
FAX VARCHAR2(80 BYTE),
CUSTOMER_ID NUMBER(15),
SUPPLIER_ID NUMBER(15),
WEB_PASSWORD VARCHAR2(240 BYTE),
USER_GUID RAW(16),
GCN_CODE_COMBINATION_ID NUMBER(15),
PERSON_PARTY_ID NUMBER
)
insert statements
Code:
Insert into APPLSYS.FND_USER
(USER_ID, USER_NAME, LAST_UPDATE_DATE, LAST_UPDATED_BY, CREATION_DATE, CREATED_BY, LAST_UPDATE_LOGIN, ENCRYPTED_FOUNDATION_PASSWORD, ENCRYPTED_USER_PASSWORD, SESSION_NUMBER, START_DATE, DESCRIPTION, PASSWORD_LIFESPAN_DAYS, EMPLOYEE_ID, EMAIL_ADDRESS, PERSON_PARTY_ID)
Values
(2248, 'MONTY.BILCHITZ@MACSTEEL.CO.ZA', TO_DATE('11/02/2009 17:16:40', 'MM/DD/YYYY HH24:MI:SS'), 1234, TO_DATE('11/02/2009 17:16:40', 'MM/DD/YYYY HH24:MI:SS'), 1234, 3349708, 'ZHDF800E989435A83F862A9078E485E76CC82E51B508395BA3B492F48235BA712864AD0586670C82FA25C6597CC6560EF3D8', 'ZHC7A20CCEEC34081812AB931A0EBD4B5205F68AF5C1BA4FDD4A682F487D61B2CF755672F2C46BAF6717D5C578B3858DFC79', 0, TO_DATE('11/02/2009 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 'Monty Bilchitz', 30, 10262, 'monty.bilchitz@macsteel.co.za', 39299);
Insert into APPLSYS.FND_USER
(USER_ID, USER_NAME, LAST_UPDATE_DATE, LAST_UPDATED_BY, CREATION_DATE, CREATED_BY, LAST_UPDATE_LOGIN, ENCRYPTED_FOUNDATION_PASSWORD, ENCRYPTED_USER_PASSWORD, SESSION_NUMBER, START_DATE, DESCRIPTION, LAST_LOGON_DATE, PASSWORD_DATE, PASSWORD_LIFESPAN_DAYS, EMPLOYEE_ID, EMAIL_ADDRESS, CUSTOMER_ID, PERSON_PARTY_ID)
Values
(2227, 'JUANITA.MOLDEHNKE@MACTRADING.CO.ZA', TO_DATE('04/13/2010 12:39:04', 'MM/DD/YYYY HH24:MI:SS'), 2227, TO_DATE('11/02/2009 09:53:38', 'MM/DD/YYYY HH24:MI:SS'), 1295, 2227, 'ZH314A0F96175B5CDB8974DC680D364364C2C05AB28C8CCDF33AE6087FE0EFC2AA8CF2FC802A139AB0F9A6CCD371F500A38E', 'ZHBB417F192253772E4971BF55465F80F1A2794F2D468B4D94D7A16EABD2FE754F9DA64268FD614BC58FDBF7457BC137C901', 252, TO_DATE('11/02/2009 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 'Juanita Moldehnke', TO_DATE('04/21/2010 07:48:00', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('04/13/2010 12:39:04', 'MM/DD/YYYY HH24:MI:SS'), 30, 12541, 'JUANITA.MOLDEHNKE@MACTRADING.CO.ZA', 81685, 81685);
Insert into APPLSYS.FND_USER
(USER_ID, USER_NAME, LAST_UPDATE_DATE, LAST_UPDATED_BY, CREATION_DATE, CREATED_BY, LAST_UPDATE_LOGIN, ENCRYPTED_FOUNDATION_PASSWORD, ENCRYPTED_USER_PASSWORD, SESSION_NUMBER, START_DATE, DESCRIPTION, LAST_LOGON_DATE, PASSWORD_DATE, PASSWORD_LIFESPAN_DAYS, EMPLOYEE_ID, EMAIL_ADDRESS, CUSTOMER_ID, PERSON_PARTY_ID)
Values
(2267, 'TANYA.SWANEPOEL@VRN.CO.ZA', TO_DATE('03/29/2010 11:13:59', 'MM/DD/YYYY HH24:MI:SS'), 2267, TO_DATE('11/24/2009 11:11:23', 'MM/DD/YYYY HH24:MI:SS'), 1295, 2267, 'ZH08DD1A68B37CAE173579A0B536B0B005F015185C3ED3E01C928F0990B602528C11560665E0EDB8EE8A666351A134D2D40C', 'ZHF50C9B4A60ED037DAD731FE2206B59B4F7305CD647BF6793AA859BB1DFFC18DCC823D6CF4DB43A94C5DBF696774FA37C00', 123, TO_DATE('11/24/2009 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 'Tanya Swanepoel', TO_DATE('04/21/2010 08:33:45', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('03/29/2010 11:13:59', 'MM/DD/YYYY HH24:MI:SS'), 30, 13003, 'TANYA.SWANEPOEL@VRN.CO.ZA', 92735, 92735);
Insert into APPLSYS.FND_USER
(USER_ID, USER_NAME, LAST_UPDATE_DATE, LAST_UPDATED_BY, CREATION_DATE, CREATED_BY, LAST_UPDATE_LOGIN, ENCRYPTED_FOUNDATION_PASSWORD, ENCRYPTED_USER_PASSWORD, SESSION_NUMBER, START_DATE, DESCRIPTION, LAST_LOGON_DATE, PASSWORD_DATE, PASSWORD_LIFESPAN_DAYS, EMPLOYEE_ID, EMAIL_ADDRESS, CUSTOMER_ID, PERSON_PARTY_ID)
Values
(2329, 'SIMANGELE.MHLONGO@MACTRADING.CO.ZA', TO_DATE('04/19/2010 14:33:11', 'MM/DD/YYYY HH24:MI:SS'), 2329, TO_DATE('03/02/2010 12:24:59', 'MM/DD/YYYY HH24:MI:SS'), 1295, 2329, 'ZHE12D2BA87DD3A97F7D17BBD5E5520F903D6C6C92B60021E3F065799E5D7DD3E163699B634050247C981BE0F8FDA81A1559', 'ZH1C22DD76D2FC5967ABFDDA4F3A5298CE9F774B061823C2F566E816C9EDB16F19225D62E85D4DB3FD73DC9DBACA2C7D2426', 91, TO_DATE('03/02/2010 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 'Simangele Mhlongo', TO_DATE('04/21/2010 09:07:54', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('04/07/2010 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 30, 6834, 'simangele.mhlongo@mactrading.co.za', 16126, 16126);
Insert into APPLSYS.FND_USER
(USER_ID, USER_NAME, LAST_UPDATE_DATE, LAST_UPDATED_BY, CREATION_DATE, CREATED_BY, LAST_UPDATE_LOGIN, ENCRYPTED_FOUNDATION_PASSWORD, ENCRYPTED_USER_PASSWORD, SESSION_NUMBER, START_DATE, DESCRIPTION, EMPLOYEE_ID, EMAIL_ADDRESS, PERSON_PARTY_ID)
Values
(2330, 'SHIELAGH.LAWLOR@MACTRADING.CO.ZA', TO_DATE('03/02/2010 12:27:42', 'MM/DD/YYYY HH24:MI:SS'), 1295, TO_DATE('03/02/2010 12:27:42', 'MM/DD/YYYY HH24:MI:SS'), 1295, 5737933, 'ZH61262B400C49CA3F72F7D5036FB5F33302093CCEFA1770AEF927F78222E10A615A4DD2B1F4D3AC7009E3A15879C7EADB70', 'ZH7B252AB5D0BA865795AF26CABD5CC6EBEF98458E3A82ECD11887E7EB89C7461BBE9C356753F88D35DF8B6CE7C0EDC062D3', 0, TO_DATE('03/02/2010 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 'Sheilagh Lawlor', 3592, 'SHIELAGH.LAWLOR@MACTRADING.CO.ZA', 8475);
Current SQL:
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,
mm,
tot AS total
FROM (SELECT TO_CHAR (CREATION_DATE, 'MM') mm, COUNT (1) AS tot
FROM applsys.fnd_user@MAC1PROD_APPLSYS.MACSTEEL.COM
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 (CASE when mm IS NULL THEN total ELSE 0 END) AS total
FROM t1)
SELECT jan, feb, mar, apr, may, jun, jul, aug, sep, oct, nov, dec, total
FROM t1
UNION ALL
SELECT jan, feb, mar, apr, may, jun, jul, aug, sep, oct, nov, dec, total
FROM t2;
current output:
Code:
JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, DEC,TOTAL
----,----,----,----,----,----,----,----,----,----,----,----,-----
2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2
0, 0, 18, 0, 0, 0, 0, 0, 0, 0, 0, 0, 18
0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 21
2, 0, 18, 1, 0, 0, 0, 0, 0, 0, 0, 0, 21
I would like too add a columns total like this example:
Code:
JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, DEC,TOTAL
------------------------------------,----,----,----,----,----,----,----,----,----,----,----,----,-----
4, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 6
0, 3, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 4
TOTAL 4, 3, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 10
Any help will be highly appreciated.
thank you