HackerRank-My SQL
Prepare > SQL > Aggregation > Weather Observation Station 13
stem_sw
2023. 5. 18. 20:28
Weather Observation Station 13 | HackerRank
Query the sum of Northern Latitudes having values greater than 38.7880 and less than 137.2345, truncated to 4 decimal places.
www.hackerrank.com
문제
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.
=> LAT_N의 합을 쿼리해 소숫점 아래 4자리에서 잘라라.
- 소숫점 아래 4번째 까지는 보여야 함.
코드
SELECT TRUNCATE(SUM(LAT_N), 4) FROM STATION
WHERE LAT_N > 38.7880 AND LAT_N < 137.2345;
- TRUNCATE( ~~, n): ~~를 소숫점 아래 n자리에서 절사
노트
TRUNCATE() 함수
TRUNCATE(A, n) # A를 소숫점 아래 n자리까지 나태내고 나머지는 절사(버림)
두 번째 시도
SELECT TRUNCATE(SUM(LAT_N),4) FROM STATION
WHERE LAT_N BETWEEN 38.7880 AND 137.2345;
- 엄밀히 생각하면, 양 끝 범위가 포함되기 때문에 정확한 쿼리는 아님