Skip to Main Content

SQL & PL/SQL

Oracle Pivot

user9311128May 26 2021

I have employee name and salary date fields in a table having only these two values. Need the salary date output in pivot row format, can anyone please help? Pasted the sample queries and the expected output format below.

create table testdaterows (empname varchar2(30), salary_dt date);
insert into testdaterows values ('peter', to_date('01/01/2021','MM/DD/YYYY'));
insert into testdaterows values ('peter', to_date('02/01/2021','MM/DD/YYYY'));
insert into testdaterows values ('peter', to_date('05/01/2021','MM/DD/YYYY'));
insert into testdaterows values ('rachael', to_date('01/10/2021','MM/DD/YYYY'));
insert into testdaterows values ('rachael', to_date('03/10/2021','MM/DD/YYYY'));
insert into testdaterows values ('rachael', to_date('04/10/2021','MM/DD/YYYY'));
insert into testdaterows values ('Anita', to_date('02/15/2021','MM/DD/YYYY'));
insert into testdaterows values ('Anita', to_date('03/15/2021','MM/DD/YYYY'));
commit;
select * from testdaterows;
Empname Salary_dt
peter 1/1/2021
peter 2/1/2021
peter 5/1/2021
rachael 1/10/2021
rachael 3/10/2021
rachael 4/10/2021
Anita 2/15/2021
Anita 3/15/2021

Expected Output:
image.png
--Thanks

This post has been answered by Frank Kulash on May 26 2021
Jump to Answer
Comments
Post Details
Added on May 26 2021
2 comments
44 views