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(IF(occupation = "Doctor", name, NULL)) AS "Doctor",
MIN(IF(occupation = "Professor", name, NULL)) AS "Professor",
MIN(IF(occupation = "Singer", name, NULL)) AS "Singer",
MIN(IF(occupation = "Actor", name, NULL)) AS "Actor"
FROM
(
SELECT
name,
occupation,
ROW_NUMBER() OVER(PARTITION BY occupation ORDER BY name) AS indexing
FROM occupations
) AS short_table
GROUP BY indexing
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(IF(occupation = "Doctor", name, NULL)) AS "Doctor", MIN(IF(occupation = "Professor", name, NULL)) AS "Professor", MIN(IF(occupation = "Singer", name, NULL)) AS "Singer", MIN(IF(occupation = "Actor", name, NULL)) AS "Actor" FROM ( SELECT name, occupation, ROW_NUMBER() OVER(PARTITION BY occupation ORDER BY name) AS indexing FROM occupations ) AS short_table GROUP BY indexing