Ollivander's Inventory

  • + 0 comments

    -- query to print id,age,coins_need and power of the wands sorted by order of descending power -- if power is same sort the results by descending age --lets get a CTE for minimum coins needed WITH coins_min AS ( SELECT code, power, MIN(coins_needed) AS minimum_coins FROM wands GROUP BY code, power ) SELECT w.id, p.age, w.coins_needed, w.power FROM wands w JOIN wands_property p ON w.code = p.code JOIN coins_min c ON w.code = c.code AND w.power = c.power WHERE p.is_evil = 0 AND w.coins_needed = c.minimum_coins ORDER BY w.power DESC, p.age DESC;