Home » SQL & PL/SQL » SQL & PL/SQL » Put row results to column format
Put row results to column format [message #408751] Wed, 17 June 2009 09:46 Go to next message
uicmxz
Messages: 48
Registered: July 2006
Member
I have data in two tables:

select grp_sk, grp_id, grp_nm from dim_group

GRP_SK|GRP_ID|GRP_NM
765|XYZ|LEVEL1 3
123|DEF|TOP MOST
789|EFG|LEVEL 1 1
896|BDE|LEVEL1 3
234|FDA|LEVEL2 1
567|XYZ|LEVEL2 2
345|WYZ|LEVEL3 1
654|ABC|NEW NAME

select PRNT_GRP_SK, CHL_GRP_SK, GRP_LVL_NBR,TOP_MOST_IND,BTTM_MOST_IND
from group_gridge

PRNT_GRP_SK|CHL_GRP_SK|GRP_LVL_NBR|TOP_MOST_IND|BTTM_MOST_IND
123|654|1|Y|N
654|654|0|N|N
654|234|1|N|Y
765|765|0|N|N
765|345|1|N|Y
765|889|1|N|Y
123|765|1|Y|N
123|123|0|Y|N
123|789|1|Y|Y
123|896|1|Y|Y
123|234|2|Y|Y
789|789|0|N|Y
896|896|0|N|Y
234|234|0|N|Y
345|345|0|N|Y
889|889|0|N|Y
123|889|2|Y|Y
123|345|2|Y|Y

I want to display as:
"PAR_GRP_ID" "CHLD_GRP_ID" "CHLD_GRP_ID1" "CHLD_GRP_ID2"
'DEF' XYZ WYZ BPE
DEF ABC FDA FAG
XYZ WYZ BPA
ABC FDA FAG
Re: Put row results to column format [message #408753 is a reply to message #408751] Wed, 17 June 2009 10:58 Go to previous message
Michel Cadot
Messages: 64103
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Please read OraFAQ Forum Guide, especially "How to format your post?" section.
Make sure that lines of code do not exceed 80 characters when you format.
Indent the code (See SQL Formatter), use code tags and align the columns in result.
Use the "Preview Message" button to verify.
Also always post your Oracle version (4 decimals).

Post a working Test case: create table and insert statements along with the result you want with these data.

Regards
Michel
Previous Topic: insert using Case When
Next Topic: Invalid Datatype
Goto Forum:
  


Current Time: Sun Dec 04 10:36:48 CST 2016

Total time taken to generate the page: 0.09630 seconds