본문 바로가기
CODING TEST/SQL : HackerRank

[MYSQL] Weather Observation Station 2

by 주 녕 2021. 8. 9.
반응형

 

▶ SQL  >  Aggregation  > Weather Observation Station 2 

 

 Problem 

Query the following two values from the STATION table:

  1. The sum of all values in LAT_N rounded to a scale of 2 decimal places. 
    → LAT_N의 모든 값의 합을 소수점 2자리까지 반올림한 값
  2. The sum of all values in LONG_W rounded to a scale of 2 decimal places.
    → LONG_W의 모든 값의 합을 소수점 2잘까지 반올림한 값

Input Format

The STATION table is described as follows:

where LAT_N is the northern latitude and LONG_W is the western longitude.

 

Output Format

Your results must be in the form:  lat lon

where lat is the sum of all values in LAT_N and lon is the sum of all values in LONG_W.

Both results must be rounded to a scale of 2 decimal places.

 

 My Answer 

SELECT ROUND(SUM(LAT_N), 2), ROUND(SUM(LONG_W), 2)
FROM STATION

 

 NOTE 

반올림을 하는 함수 ROUND()와 합을 구하는 함수 SUM()을 사용하면 해결되는 문제이다!

MYSQL의 숫자 함수는 아래 포스팅에 정리되어 있으니 참고!

 

[MYSQL] The Blunder

SQL > Aggregation > The Blunder  Problem Samantha was tasked with calculating the average monthly salaries for all employees in the EMPLOYEES table, but did not realize her keyboard's 0 key was b..

junyoung-developer.tistory.com

 

반응형

'CODING TEST > SQL : HackerRank' 카테고리의 다른 글

[MYSQL] Placements  (0) 2022.10.05
[MYSQL] New Companies  (2) 2022.09.30
[MYSQL] Weather Observation Station 13  (0) 2021.08.16
[MYSQL] Top Earners  (0) 2021.05.26
[MYSQL] The Blunder  (0) 2021.05.18
[MYSQL] Population Density Difference  (0) 2021.05.13
[MYSQL] Japan Population  (0) 2021.05.13
[MySQL] Average Population  (0) 2021.04.21

댓글