Ollivander's Inventory

  • + 0 comments
    with tmp as (
        select power, age, w.code, min(coins_needed) as price
        from wands as w
        inner join wands_property as wp on w.code = wp.code
        where is_evil = 0
        group by power, age, w.code
    )
    select id, age, price, tmp.power
    from tmp
    inner join wands as w on tmp.power = w.power and tmp.code = w.code
    and price = coins_needed
    order by tmp.power desc, age desc;