[HackerRank MySQL] Weather Observation Station 2, 13-17 - ROUND & TRUNCATE (Basic)

2021. 1. 5. 22:40Today I Learned.../MySQL

Weather Observation Station 2

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.
  2. The sum of all values in LONG_W rounded to a scale of 2 decimal places.

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.

select round(sum(lat_n), 2), round(sum(long_w), 2)
from station

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.

select truncate(sum(lat_n), 4)
from station
where lat_n > 38.7880 and lat_n < 137.2345
ROUND(숫자, 자릿수) 자릿수 + 1 에서 반올림
TRUNCATE(숫자, 자릿수) 자릿수 아래로 버림

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.

select truncate(max(lat_n), 4)
from station
where lat_n < 137.2345

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.

select round(long_w, 4)
from station
where lat_n < 137.2345
order by lat_n desc
limit 1

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.

select round(min(lat_n), 4)
from station
where lat_n > 38.7780

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.

select round(long_w, 4)
from station
where lat_n = (select min(lat_n) from station where lat_n > 38.7780)

문제출처: 해커랭크