Ollivander's Inventory

  • + 0 comments
    /* MS - SQL Server */
    with cte as
    (
    select
        w.id,
        wp.age,
        w.coins_needed,
        w.power,
        dense_rank() over(partition by w.power, wp.age order by w.coins_needed) dr
    from
        Wands w
    left join Wands_Property wp on w.code = wp.code
    where
        wp.is_evil = 0
    )
    select id, age, coins_needed, power
    from cte
    where dr = 1
    order by
        power desc,
        age desc;