We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
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
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Ollivander's Inventory
You are viewing a single comment's thread. Return to all 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