Ollivander's Inventory

  • + 0 comments
    SELECT w.id, wp.age, w.coins_needed, w.power
    FROM Wands w
    JOIN Wands_Property wp ON w.code = wp.code
    JOIN (
        SELECT wp.age, MIN(w.coins_needed) AS min_gold, w.power
        FROM Wands w
        JOIN Wands_Property wp ON w.code = wp.code
        WHERE wp.is_evil = 0
        GROUP BY wp.age, w.power
    ) mc ON wp.age = mc.age 
         AND w.power = mc.power 
         AND w.coins_needed = mc.min_gold
    ORDER BY w.power DESC, wp.age DESC;