Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

pivot row to column from multiple groups

Nicks123May 11 2021 — edited May 11 2021

Hi Experts,
I hope you and your family are doing well.
I had a request to format the data like a pivot clause, each strata(yrs, mth, group_id, type) has a unique name and I like to list the names_total as columns.
here is the example:
CREATE TABLE T1
(YRS NUMBER,
MTH NUMBER,
TYPE NUMBER,
GROUP_ID NUMBER,
name VARCHAR2(26 BYTE),
TOT NUMBER);
Insert into T1 (YRS,MTH,GROUP_ID,TYPE,name,TOT) values (2020,1,0,1,'James',1);
Insert into T1 (YRS,MTH,GROUP_ID,TYPE,name,TOT) values (2020,1,0,1,'scott',371);
Insert into T1 (YRS,MTH,GROUP_ID,TYPE,name,TOT) values (2020,1,0,1,'yelen',13);
Insert into T1 (YRS,MTH,GROUP_ID,TYPE,name,TOT) values (2020,1,1,1,'James',6);
Insert into T1 (YRS,MTH,GROUP_ID,TYPE,name,TOT) values (2020,1,1,1,'scott',522);
Insert into T1 (YRS,MTH,GROUP_ID,TYPE,name,TOT) values (2020,1,1,1,'yelen',32);
Insert into T1 (YRS,MTH,GROUP_ID,TYPE,name,TOT) values (2020,1,1,2,'scott',0.5);
Insert into T1 (YRS,MTH,GROUP_ID,TYPE,name,TOT) values (2020,1,1,2,'yelen',0);
Insert into T1 (YRS,MTH,GROUP_ID,TYPE,name,TOT) values (2020,1,2,1,'scott',123);
Insert into T1 (YRS,MTH,GROUP_ID,TYPE,name,TOT) values (2020,1,2,1,'yelen',10);
Insert into T1 (YRS,MTH,GROUP_ID,TYPE,name,TOT) values (2020,1,2,1,'baker',0.2);
select * from T1
image.pngand like to format the data like this:
image.png
Thanks in advance,

Nick

This post has been answered by Solomon Yakobson on May 12 2021
Jump to Answer
Comments
Post Details
Added on May 11 2021
10 comments
629 views