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,w.coins_needed,w.power from wands w
left join wands_property wp
on w.code=wp.code
where wp.is_evil=0 and
w.coins_needed IN (select Min(w1.coins_needed)
from wands w1
left join wands_property wp1
on w1.code=wp1.code
where wp1.is_evil=0
and wp1.age=wp.age
and w1.power=w.power)
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 →
My SQL Query:
This will work.
select w.id,wp.age,w.coins_needed,w.power from wands w left join wands_property wp on w.code=wp.code where wp.is_evil=0 and w.coins_needed IN (select Min(w1.coins_needed) from wands w1 left join wands_property wp1 on w1.code=wp1.code where wp1.is_evil=0 and wp1.age=wp.age and w1.power=w.power) order by w.power DESC,wp.age DESC