Ollivander's Inventory

  • + 0 comments

    MySql 5.7

    SELECT
        w.id,
        wp.age,
        w.coins_needed,
        w.power
    FROM wands w
        JOIN wands_property wp ON wp.code = w.code
    WHERE wp.is_evil = 0 AND w.coins_needed = (
        SELECT
            MIN(coins_needed)
        FROM wands derived_w
        JOIN wands_property derived_wp ON derived_wp.code = derived_w.code
        WHERE derived_wp.age = wp.age AND derived_w.power = w.power
    )
    ORDER BY w.power DESC, wp.age DESC
    ;