HackerRank(해커랭크) Population Density Difference, Weather Observation Station 12, Weather Observation Station 14, Top Competitors

Kim So-Myoung·2024년 2월 15일
0
post-thumbnail

Population Density Difference

SELECT MAX(POPULATION) - MIN(POPULATION)
FROM CITY

Weather Observation Station 12

SELECT DISTINCT CITY
  FROM STATION
 WHERE LEFT(CITY,1) NOT IN ('A','E','I','O','U')
    OR RIGHT(CITY,1) NOT IN ('a','e','i','o','u')

that either do not start with vowels : LEFT(CITY,1) NOT IN ('A','E','I','O','U')
or
do not end with vowels : RIGHT(CITY,1) NOT IN ('a','e','i','o','u')
Your result cannot contain duplicates. : DISTINCT

Weather Observation Station 14

SELECT TRUNCATE(SUM(LAT_N),4)
FROM STATION
WHERE LAT_N > 38.7880 AND LAT_N < 137.2345

greater than A and less than B : LAT_N > A AND LAT_N < B
A와 B는 포함하지 않음
A, B 포함할 경우에만: WHERE LAT_N BETWEEN A AND B
Truncate your answer to 4 decimal places.: TRUNCATE(SUM(LAT_N),4)

Top Competitors

    SELECT S.hacker_id, H.name
      FROM Submissions S
INNER JOIN Challenges C
        ON S.challenge_id = C.challenge_id
INNER JOIN Difficulty D
        ON C.difficulty_level = D.difficulty_level
INNER JOIN Hackers H
        ON S.hacker_id = H.hacker_id
     WHERE S.score = D.score
  GROUP BY S.hacker_id, H.name
    HAVING COUNT(S.challenge_id) > 1
  ORDER BY COUNT(S.challenge_id) DESC, S.hacker_id

✔ 오답노트
challenge_id is the id of the challenge that the submission belongs to: 문제에 join 조건에 대한 정보 challenge_id만 언급하고 있음.
Submissions와 Challenges join 시 challenge_id만 join 해야한다.
Submissions와 만든 해커와 Challenges를 만든 해커는 당연히 다르므로, hacker_id를 join 하면 안된다.

profile
Full-Stack Engineer

0개의 댓글