matrix query for dates
Hello Everyone,
I would like to write a query which produce me following result:
I have tried pivot function but not able to produce any result, any help will be appreciated.
WITH pivot_data AS (
SELECT BUDGET_DATE,LEASE_INCOME_GL,LEASE_INCOME
FROM AA_BUDGET_TEST
)
SELECT *
FROM pivot_data
PIVOT (
SUM(LEASE_INCOME)
FOR BUDGET_DATE
IN (select budget_date from aa_budget_test)
);
Budget date | ||||||||||||
1-Jan-17 | 1-Feb-17 | 1-Mar-17 | 1-Apr-17 | 1-May-17 | 1-Jun-17 | 1-Jul-17 | 1-Aug-17 | 1-Sep-17 | 1-Oct-17 | 1-Nov-17 | 1-Dec-17 | |
LEASE_INCOME_GL | ||||||||||||
LEASE_INCOME | ||||||||||||
LEASE_INCOME_BUDGET | ||||||||||||
PF_INCOME_GL | ||||||||||||
PF_INCOME | ||||||||||||
PF_INCOME_BUDGET |
The table script and data as bellow: