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.
WITH rankedWands AS (
SELECT
W.id,
W.code,
WP.age,
W.coins_needed,
W.power,
RANK() OVER (PARTITION BY W.code, WP.age ,w.power ORDER BY W.coins_needed ASC) AS rank
FROM
Wands AS W
INNER JOIN
Wands_Property AS WP
ON W.code = WP.code
WHERE
WP.is_evil = 0
)
SELECT
id,
age,
coins_needed,
power
FROM
rankedWands
WHERE
rank = 1 -- Selects the rows with the minimum coins_needed per code and age
ORDER BY
power DESC,
age DESC;
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Ollivander's Inventory
You are viewing a single comment's thread. Return to all comments →
WITH rankedWands AS ( SELECT W.id, W.code, WP.age, W.coins_needed, W.power, RANK() OVER (PARTITION BY W.code, WP.age ,w.power ORDER BY W.coins_needed ASC) AS rank FROM Wands AS W INNER JOIN Wands_Property AS WP ON W.code = WP.code WHERE WP.is_evil = 0 ) SELECT id, age, coins_needed, power FROM rankedWands WHERE rank = 1 -- Selects the rows with the minimum coins_needed per code and age ORDER BY power DESC, age DESC;