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
MAX(CASE WHEN occupation = 'Doctor' THEN name ELSE NULL END) AS Doctor,
MAX(CASE WHEN occupation = 'Professor' THEN name ELSE NULL END) AS Professor,
MAX(CASE WHEN occupation = 'Singer' THEN name ELSE NULL END) AS Singer,
MAX(CASE WHEN occupation = 'Actor' THEN name ELSE NULL END) AS Actor
FROM (
SELECT
name, occupation,
ROW_NUMBER() OVER(PARTITION BY occupation ORDER BY name) AS row_numb
FROM occupations
) AS numbered_rows
GROUP BY row_numb
ORDER BY row_numb
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 →
MySQL solution