imhamburger 님의 블로그
해커랭크 SQL - Ollivander's Inventory 문제풀이 본문
문제
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.
Ollivander's Inventory | HackerRank
Help pick out Ron's new wand.
www.hackerrank.com
대충 요약하자면, 최소의 돈으로 high age와 high power 를 가진 지팡이를 골라야 한다.
문제풀이
SELECT W.id, P.age, W.coins_needed, W.power
FROM Wands W
JOIN Wands_Property P ON W.code = P.code
WHERE P.is_evil = 0
AND W.coins_needed = (
SELECT MIN(W1.coins_needed)
FROM Wands W1
JOIN Wands_Property P1 ON W1.code = P1.code
WHERE P1.is_evil = 0
AND W1.power = W.power AND P1.age = P.age)
ORDER BY power DESC, age DESC;
해커랭크 처음으로 풀어보았는데 괜찮은 것 같다. (영어인 것 빼고는....)
SQL 연습은 해커랭크에서 해봐야겠다..!!
'Mysql' 카테고리의 다른 글
| 해커랭크 - Weather Observation Station 20 문제풀이 (0) | 2025.12.03 |
|---|---|
| 해커랭크 - BST 문제 풀이 (0) | 2025.11.30 |
| Mysql - 특정 기간동안 대여 가능한 자동차들의 대여비용 구하기 문제풀이 (0) | 2025.03.10 |
| Mysql - 프로그래머스 진료과별 총 예약 횟수 출력하기 문제풀이 (0) | 2025.03.04 |
| Mysql - 그룹별 조건에 맞는 식당 목록 출력하기 문제풀이 (0) | 2025.02.19 |