Skip to content
Advertisement

Change Two Rows Into Two Columns

Oracle newbie here just trying to learn something.

I have a query that returns two rows per ID:

Current Output

enter image description here

Instead of two rows, how can I put the two varying values in the B1_CHECKLIST_COMMENT column into two separate columns?

Visually, here’s what I’m looking to achieve:

Desired Output

I’m using Oracle version 12.1.

Advertisement

Answer

You can use PIVOT:

Or conditional aggregation:

Which, for the sample data:

Both output:

B1_ALT_ID B1_CHECKLIST_1 B1_CHECKLIST_2
DIF13-003 736 Library
DIF13-001 27654 Fiber
DIF13-002 1380 Water

db<>fiddle here

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement