Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Convert vertical table to horizontal in oracle

I have the following table format.

POLNO NAME PRM
12100 PRMA 161410
12100 PRMB 0
12100 PRMC 0
12100 PRMD 80

I need to convert this table to follow.

POLNO PRMA PRMB PRMC PRMD
12100 161410 0 0 80

Anyone have an idea how to do this?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You may use pivoting logic:

SELECT
    POLNO,
    MAX(CASE WHEN NAME = 'PRMA' THEN PRM END) AS PRMA,
    MAX(CASE WHEN NAME = 'PRMB' THEN PRM END) AS PRMB,
    MAX(CASE WHEN NAME = 'PRMC' THEN PRM END) AS PRMC,
    MAX(CASE WHEN NAME = 'PRMD' THEN PRM END) AS PRMD
FROM yourTable
GROUP BY POLNO;
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading