Issue
Tabl: Occupation (Name, Profession)
Name Profession
Zahid Engineer
Rakib Doctor
David Singer
Farid Player
Arif Doctor
Tarik Singer
Expected Output:
Doctor Engineer Singer Player
Rakib Zahid David Farid
Arif NULL Tarik NULL
I tried:
Select Doctor, Engineer, Singer, Player
from
( Select [Name], Profession from Occupation ) T1
PIVOT
(Max([Name]) for Profession IN ( Doctor, Engineer, Singer, Player)) T2
But, It output only 1 row:
Doctor Engineer Singer Player
Rakib Zahid Tarik Farid
Solution
With no GTD of order
Select *
From (
Select [Name]
,[Profession]
,RN = row_number() over (partition by Profession order by Profession)
from Occupation
) src
Pivot (Max([Name]) for Profession IN ( Doctor, Engineer, Singer, Player)) pvt
Results
RN Doctor Engineer Singer Player
1 Rakib Zahid David Farid
2 Arif NULL Tarik NULL
Answered By - John Cappelletti Answer Checked By - Timothy Miller (PHPFixing Admin)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.