Saturday, January 9, 2021

How to convert rows to columns in SQL (Oracle DB)?

 Input:

Expected Output:



Query:

UNPIVOT_TABLE Data:

SELECT * FROM 

    (SELECT * 

        FROM UNPIVOT_TABLE) 

        PIVOT (MAX(SALES) FOR QUARTER IN ('Q1' AS Q1,'Q2' AS Q2,'Q3' AS Q3,'Q4' AS Q4));

No comments:

Post a Comment