Please help me in converting my rows into columns and not duplicating them. I've been searching and applying for ways to do this but I cannot satisfy my requirement.
create table PROGRAMMER
(
PERSON varchar(15),
LANGUAGE varchar(20),
LEVELS varchar(15)
);
insert into PROGRAMMER (PERSON, LANGUAGE, LEVELS) values ('CARL', 'JAVA', 'SENIOR');
insert into PROGRAMMER (PERSON, LANGUAGE, LEVELS) values ('CARL', 'PHP', 'MID');
insert into PROGRAMMER (PERSON, LANGUAGE, LEVELS) values ('CARL', 'VB.NET', 'JUNIOR');
insert into PROGRAMMER (PERSON, LANGUAGE, LEVELS) values ('GARY', 'C#', 'MID');
insert into PROGRAMMER (PERSON, LANGUAGE, LEVELS) values ('GARY', 'VB.NET', 'MID');
insert into PROGRAMMER (PERSON, LANGUAGE, LEVELS) values ('RALPH', 'PHP', 'SENIOR');
insert into PROGRAMMER (PERSON, LANGUAGE, LEVELS) values ('RALPH', 'RUBY', 'JUNIOR');
insert into PROGRAMMER (PERSON, LANGUAGE, LEVELS) values ('RALPH', 'JAVASCRIPT', 'SENIOR');
I want to represent the table like this using "LEVELS" as the column with some rows having the same person as many times as they have the same levels in different languages. The other columns will be empty if there is no entry.
| PERSON | SENIOR | MID | JUNIOR |
----------------------------------------------
| CARL | JAVA | PHP | VB.NET |
| GARY | | C# | |
| GARY | | VB.NET | |
| RALPH | PHP | | RUBY |
| RALPH |JAVASCRIPT| | |
Thank you.
it is good challenge in designing subqueries, try this query on your table
PROGRAMMER
as you said:You cannot achieve this with transpose. rather try using
natural full outer join
You get
Try this if you have definitive list of languages