SQL Language (MOSC)

MOSC Banner

matrix query for dates

edited Jul 5, 2018 9:09AM in SQL Language (MOSC) 2 commentsAnswered

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-171-Feb-171-Mar-171-Apr-171-May-171-Jun-171-Jul-171-Aug-171-Sep-171-Oct-171-Nov-171-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:

Tagged:

Howdy, Stranger!

Log In

To view full details, sign in to My Oracle Support Community.

Register

Don't have a My Oracle Support Community account? Click here to get started.

Category Leaderboard

Top contributors this month

New to My Oracle Support Community? Visit our Welcome Center

MOSC Help Center