Q7_m

 avatar
kuber
plain_text
2 years ago
633 B
2
Indexable
Never
select
    w.id, 
    wp.age,
    w.coins_needed,
    w.power
from wands w
    inner join wands_property wp on w.code = wp.code
    /* first condition gets the wand that are not evil and the second condition gets that wand              that need minimum number of coins among a group of wands with same age and power.  */
where wp.is_evil = 0 and 
        w.coins_needed = (select min(w2.coins_needed) 
                          from wands w2 
                            inner join wands_property wp2 on w2.code = wp2.code 
                          where w2.power = w.power and wp2.age = wp.age)
order by w.power desc, wp.age desc;