SQL 50

Ollivander's Inventory

문제 풀이 링크: https://www.hackerrank.com/challenges/harry-potter-and-wands/problem?isFullScreen=true Ollivander's Inventory | HackerRankHelp pick out Ron's new wand.www.hackerrank.com 🧙🏻‍♀️ 문제 요약각 (power, age) 조합에 대해 가장 적은 coins_needed인 wand만 고르기비-사악한(wands_property.is_evil = 0) 것만 고려최종적으로 출력할 열: id, age, coins_needed, power정렬: power 내림차순, power가 같으면 age 내림차순SELECT w.id, wp.age, w.coins_need..

SQL 2025.05.06

Symmetric Pairs

문제 풀이 링크: https://www.hackerrank.com/challenges/symmetric-pairs/problem?isFullScreen=true Symmetric Pairs | HackerRankWrite a query to output all symmetric pairs in ascending order by the value of X.www.hackerrank.com풀이 과정 data1, data2 CTEfunctions 테이블을 두 번 조회각각의 쿼리에 ROW_NUMBER()를 사용하여 순서 배정 본 쿼리DISTINCT: 같은 쌍이 중복 출력되는 것 방지x1 = y2 AND y1 = x2RN1 != RN2: 같은 행끼리 매칭되는 것 방지x1 WITH data1 AS(SELECT f...

SQL 2025.05.06

The Report

문제 풀이 링크: https://www.hackerrank.com/challenges/the-report/problem?isFullScreen=true The Report | HackerRankWrite a query to generate a report containing three columns: Name, Grade and Mark.www.hackerrank.com👿 The Report 문제 요약 학생의 점수(Marks)에 따라 학점(Grade) 계산출력 컬럼: Name, Grade, Marks조건Grade가 8 이상인 경우이름(Name)은 그대로 출력정렬Grade 기준 내림차순같은 Grade 내에서는 Name 기준 오름차순Grade가 8 미만인 경우이름(Name)은 "NULL"로 대체정렬Grad..

SQL 2025.05.05

Contest Leaderboard

문제 풀이 링크: https://www.hackerrank.com/challenges/contest-leaderboard/problem?isFullScreen=true Contest Leaderboard | HackerRankGenerate the contest leaderboard.www.hackerrank.com🧾 Contest Leaderboard 문제 요약목적해커별로 각 챌린지에서 받은 최고 점수만 합산하여 총 점수(total score)를 계산하고, 총점이 0점 초과인 해커만 출력출력 항목:hacker_idnametotal_score (챌린지별 최고 점수들의 합계)정렬 기준:total_score 기준 내림차순동점일 경우 hacker_id 기준 오름차순조건:총점이 0점인 해커는 제외SELECT ..

SQL 2025.05.05

Binary Tree Nodes

문제 풀이 링크: https://www.hackerrank.com/challenges/binary-search-tree-1/problem?isFullScreen=true Binary Tree Nodes | HackerRankWrite a query to find the node type of BST ordered by the value of the node.www.hackerrank.com풀이 방법WHERE P IS NOT NULL을 사용하지 않을 경우, NULL 값이 포함될 수 있고, NOT IN 절에 NULL이 포함되면 비교 결과가 항상 FALSE 또는 UNKNOWN이 되어 의도한 결과가 나오지 않게됨SELECT N, CASE WHEN P IS NULL THEN 'Root' WHEN..

SQL 2025.05.05

Weather Observation Station 19

문제 풀이 링크: https://www.hackerrank.com/challenges/weather-observation-station-19/problem?isFullScreen=true Weather Observation Station 19 | HackerRankQuery the Euclidean Distance between two points and round to 4 decimal digits.www.hackerrank.com🔍 문제 요약LAT_N(위도), LONG_W(경도) 값을 활용해 두 좌표 사이의 유클리드 거리(직선 거리)를 구하는 문제💡 좌표 정의P₁ (a, c)a = 최소 LAT_N (위도)c = 최소 LONG_W (경도)P₂ (b, d)b = 최대 LAT_Nd = 최대 LONG_W..

SQL 2025.05.05