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.
And in MySQL too, this one has 1 JOIN instead of 2:
SELECT id, age, TT.mincoin, WANDS.power FROM WANDS
JOIN
(SELECT WANDS.code, age, WANDS.power, MIN(coins_needed) as mincoin FROM WANDS
JOIN WANDS_PROPERTY on WANDS.code = WANDS_PROPERTY.code
WHERE is_EVIL = 0
GROUP BY power, age) as TT
on TT.code = WANDS.code
WHERE TT.mincoin = WANDS.Coins_needed
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 →
And in MySQL too, this one has 1 JOIN instead of 2:
SELECT id, age, TT.mincoin, WANDS.power FROM WANDS JOIN (SELECT WANDS.code, age, WANDS.power, MIN(coins_needed) as mincoin FROM WANDS JOIN WANDS_PROPERTY on WANDS.code = WANDS_PROPERTY.code WHERE is_EVIL = 0 GROUP BY power, age) as TT on TT.code = WANDS.code WHERE TT.mincoin = WANDS.Coins_needed ORDER BY power DESC, age DESC;