Harry Potter and his friends are at Ollivander's with Ron, finally replacing Charlie's old broken wand.
Hermione decides the best way to choose is by determining the minimum number of gold galleons needed to buy each non-evil wand of high power and age. Write a query to print the id, age, coins_needed, and power of the wands that Ron's interested in, sorted in order of descending power. If more than one wand has same power, sort the result in order of descending age.
Input Format
The following tables contain data on the wands in Ollivander's inventory:
Sample Output
9 45 1647 10
12 17 9897 10
1 20 3688 8
15 40 6018 7
19 20 7651 6
11 40 7587 5
10 20 504 5
18 40 3312 3
20 17 5689 3
5 45 6020 2
14 40 5408 1
*age-power은 유니크값이다
SELECT W.ID, WP.AGE, W.COINS_NEEDED, W.POWER
FROM WANDS W JOIN WANDS_PROPERTY WP ON W.CODE = WP.CODE
WHERE WP.IS_EVIL = 0
AND W.COINS_NEEDED = (SELECT MIN(W1.COINS_NEEDED)
FROM WANDS W1 JOIN WANDS_PROPERTY WP1 ON W1.CODE = WP1.CODE
WHERE WP1.IS_EVIL = 0
AND W1.POWER = W.POWER AND WP1.AGE = WP.AGE)
ORDER BY W.POWER DESC, WP.AGE DESC ;