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.
Hermione wants to see only the minimum price for every Power/Age combination in the results which is non evil
so for each power & age combination find min_coins required and then sort
For MySql -
*/
select w.id,p.age,w.coins_needed,w.power
from wands w join wands_property p on w.code=p.code
where p.is_evil=0 and
w.coins_needed = (select min(w1.coins_needed)
from wands w1 join wands_property p1 on w1.code=p1.code
where p.is_evil=0 and
w.power=w1.power and p.code=p1.code)
order by w.power desc,p.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 →
/* display id, age, coins_needed, power where
Hermione wants to see only the minimum price for every Power/Age combination in the results which is non evil
so for each power & age combination find min_coins required and then sort
For MySql -
*/
select w.id,p.age,w.coins_needed,w.power from wands w join wands_property p on w.code=p.code where p.is_evil=0 and w.coins_needed = (select min(w1.coins_needed) from wands w1 join wands_property p1 on w1.code=p1.code where p.is_evil=0 and w.power=w1.power and p.code=p1.code) order by w.power desc,p.age desc