[해커랭크 SQL] Aggregation 문제풀이 (1)
해커랭크(HackerRank) MySQL, 난이도 EASY 6 문제 풀이
✔️ 테이블 정보
The STATION table is described as follows:
| Field | Type |
|---|---|
| ID | NUMBER |
| CITY | VARCHAR2(21) |
| STATE | VARCHAR2(2) |
| LAT_N | NUMBER |
| LONG_W | NUMBER |
where LAT_N is the northern latitude and LONG_W is the western longitude.
1. Weather Observation Station 2
Query the following two values from the STATION table:
- The sum of all values in LAT_N rounded to a scale of 2 decimal places.
- The sum of all values in LONG_W rounded to a scale of 2 decimal places.
문제 요약 : LAT_N의 모든 값 합계는 소수점 이하 2자리로 반올림, LONG_W에 있는 모든 값의 합계는 소수점 이하 2자리로 반올림하세요.
(1) 코드 작성
SELECT ROUND(SUM(LAT_N), 2), ROUND(SUM(LONG_W), 2)
FROM STATION
👉 Weather Observation Station 2 문제 보러가기
2. Weather Observation Station 13
Query the sum of Northern Latitudes (LAT_N) from STATION having values greater than 38.7880 and less than 137.2345. Truncate your answer to 4 decimal places.
문제 요약 : STATION에서 38.7880보다 크고 137.2345보다 작은 값을 갖는 북위도(LAT_N)의 합을 소수점 이하 4 자릿수로 나타내세요.
(1) 코드 작성
SELECT TRUNCATE(SUM(LAT_N), 4)
FROM STATION
WHERE LAT_N > 38.7880 AND LAT_N < 137.2345
👉 Weather Observation Station 13 문제 보러가기
3. Weather Observation Station 14
Query the greatest value of the Northern Latitudes (LAT_N) from STATION that is less than 137.2345. Truncate your answer to 4 decimal places.
문제 요약 : STATION에서 137.2345보다 작은 북위도(LAT_N)의 최대값을 소수점 4자리로 나타내세요.
(1) 코드 작성
SELECT TRUNCATE(MAX(LAT_N), 4)
FROM STATION
WHERE LAT_N < 137.2345
👉 Weather Observation Station 14 문제 보러가기
4. Weather Observation Station 15
Query the Western Longitude (LONG_W) for the largest Northern Latitude (LAT_N) in STATION that is less than 137.2345. Round your answer to 4 decimal places.
문제 요약 : STATION에서 137.2345보다 작은 가장 큰 북위(LAT_N)에 대해 서경(LONG_W)을 소수점 이하 4자리까지 반올림하세요.
(1) 코드 작성
SELECT ROUND(LONG_W, 4)
FROM STATION
WHERE LAT_N < 137.2345
ORDER BY LAT_N DESC
LIMIT 1
👉 Weather Observation Station 15 문제 보러가기
5. Weather Observation Station 16
Query the smallest Northern Latitude (LAT_N) from STATION that is greater than 38.7780. Round your answer to 4 decimal places.
문제 요약 : 38.7780보다 큰, 가장 작은 북위도(LAT_N)를 쿼리하고 답을 소수점 이하 4자리까지 반올림하세요.
(1) 코드 작성
SELECT ROUND(MIN(LAT_N), 4)
FROM STATION
WHERE LAT_N > 38.7780
👉 Weather Observation Station 16 문제 보러가기
6. Weather Observation Station 17
Query the Western Longitude (LONG_W) where the smallest Northern Latitude (LAT_N) in STATION is greater than 38.7780. Round your answer to 4 decimal places.
문제 요약 : STATION에서 북위(LAT_N)가 38.7780보다 클 때의 가장 작은 서부 경도(LONG_W)를 소수점 이하 4자리까지 반올림하세요.
(1) 코드 작성
SELECT ROUND(LONG_W, 4)
FROM STATION
WHERE LAT_N > 38.7780
ORDER BY LAT_N
LIMIT 1
👉 Weather Observation Station 17 문제 보러가기
👩🏻💻개인 공부 기록용 블로그입니다
오류나 틀린 부분이 있을 경우 댓글 혹은 메일로 따끔하게 지적해주시면 감사하겠습니다.
댓글남기기