Ollivander's Inventory

  • + 0 comments

    ngoccth_SQL SERVER: WITH table_1 AS ( SELECT id, age, MIN(coins_needed) AS Min, [power] , row_number () OVER (PARTITION BY [power], age ORDER BY MIN(coins_needed)) AS num FROM Wands LEFT JOIN Wands_Property ON Wands.code = Wands_Property.code WHERE is_evil = 0 GROUP BY id, age, [power] ) SELECT id, age, Min, [power] FROM table_1 WHERE num = 1 ORDER BY power DESC, age DESC