Ollivander's Inventory

  • + 0 comments

    WITH rankedWands AS ( SELECT W.id, W.code, WP.age, W.coins_needed, W.power, RANK() OVER (PARTITION BY W.code, WP.age ,w.power ORDER BY W.coins_needed ASC) AS rank FROM Wands AS W INNER JOIN Wands_Property AS WP ON W.code = WP.code WHERE WP.is_evil = 0 ) SELECT id, age, coins_needed, power FROM rankedWands WHERE rank = 1 -- Selects the rows with the minimum coins_needed per code and age ORDER BY power DESC, age DESC;