We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
SELECT
MIN(CASE WHEN Occupation = 'Doctor' THEN Name END) AS Doctor,
MIN(CASE WHEN Occupation = 'Professor' THEN Name END) AS Professor,
MIN(CASE WHEN Occupation = 'Singer' THEN Name END) AS Singer,
MIN(CASE WHEN Occupation = 'Actor' THEN Name END) AS Actor
FROM
(
Select Name, occupation,
ROW_NUMBER() OVER(PARTITION BY Occupation ORDER BY Name) as RowNum
FROM OCCUPATIONS
) AS Temp
GROUP BY RowNum
ORDER BY RowNum;
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Occupations
You are viewing a single comment's thread. Return to all comments →
SELECT MIN(CASE WHEN Occupation = 'Doctor' THEN Name END) AS Doctor, MIN(CASE WHEN Occupation = 'Professor' THEN Name END) AS Professor, MIN(CASE WHEN Occupation = 'Singer' THEN Name END) AS Singer, MIN(CASE WHEN Occupation = 'Actor' THEN Name END) AS Actor FROM ( Select Name, occupation, ROW_NUMBER() OVER(PARTITION BY Occupation ORDER BY Name) as RowNum FROM OCCUPATIONS ) AS Temp GROUP BY RowNum ORDER BY RowNum;