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.
--First Selcet the needed data --
SELECT W.id, WP.age, W.coins_needed, W.power
FROM Wands W
JOIN Wands_Property WP ON W.code = WP.code
-- Apply the needed Selection Condition --
-- we need the minium coins while having the same power and age ---- we also need to exculde the evil wands --
WHERE W.coins_needed = (
SELECT MIN(W1.coins_needed)
FROM Wands W1
JOIN Wands_Property WP1 ON W1.code = WP1.code
WHERE WP1.is_evil = 0
AND W1.power = W.power
AND WP1.age = WP.age
)
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 →
--First Selcet the needed data -- SELECT W.id, WP.age, W.coins_needed, W.power FROM Wands W JOIN Wands_Property WP ON W.code = WP.code -- Apply the needed Selection Condition -- -- we need the minium coins while having the same power and age -- -- we also need to exculde the evil wands -- WHERE W.coins_needed = ( SELECT MIN(W1.coins_needed) FROM Wands W1 JOIN Wands_Property WP1 ON W1.code = WP1.code WHERE WP1.is_evil = 0 AND W1.power = W.power AND WP1.age = WP.age ) ORDER BY W.power DESC, WP.age DESC;