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 w.id, wp.age, filt.cost, w.power
FROM WANDS w
JOIN WANDS_PROPERTY wp on w.code = wp.code
JOIN (
SELECT filt_wp.age, MIN(filt_w.coins_needed) AS cost, filt_w.power
FROM WANDS filt_w
JOIN WANDS_PROPERTY filt_wp on filt_w.code = filt_wp.code
WHERE filt_wp.is_evil = 0
GROUP BY filt_wp.age, filt_w.power
) AS filt ON filt.age = wp.age AND filt.power = w.power AND filt.cost = w.coins_needed
ORDER BY w.power DESC, wp.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 →
SELECT w.id, wp.age, filt.cost, w.power FROM WANDS w JOIN WANDS_PROPERTY wp on w.code = wp.code JOIN ( SELECT filt_wp.age, MIN(filt_w.coins_needed) AS cost, filt_w.power FROM WANDS filt_w JOIN WANDS_PROPERTY filt_wp on filt_w.code = filt_wp.code WHERE filt_wp.is_evil = 0 GROUP BY filt_wp.age, filt_w.power ) AS filt ON filt.age = wp.age AND filt.power = w.power AND filt.cost = w.coins_needed ORDER BY w.power DESC, wp.age DESC;