본문 바로가기
MySQL/문제풀이

[HackerRank] Japan Population / Weather Observation Station 2 / Weather Observation Station 18

by MINNI_ 2021. 3. 22.

1) Japan Population


 

1. 문제

 

Query the sum of the populations for all Japanese cities in CITY. The COUNTRYCODE for Japan is JPN.

Input Format

 

The CITY table is described as follows: 


2. 답

SELECT SUM(population)
FROM city
WHERE countrycode = "JPN"

3. KEY POINT

 

  • SUM(컬럼명) : 해당 컬럼의 합

 

 

www.hackerrank.com/challenges/japan-population/problem?h_r=internal-search

 

Japan Population | HackerRank

Query to the sum of the populations of all Japanese cities in CITY.

www.hackerrank.com


 

2) Weather Observation Station 2


1. 문제

 

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.


2. 답

SELECT ROUND(SUM(lat_n), 2) AS lat, ROUND(SUM(long_w), 2) AS lon
FROM station

3. KEY POINT

 

  • ROUND(컬럼명/값, n) : 값을 소수점 이하 n자릿수로 반올림
  • AS : 별명 붙이기

 

www.hackerrank.com/challenges/weather-observation-station-2/problem?h_r=internal-search

 

Weather Observation Station 2 | HackerRank

Write a query to print the sum of LAT_N and the sum of LONG_W separated by space, rounded to 2 decimal places.

www.hackerrank.com


 

3) Weather Observation Station 18


1. 문제

 

Consider P1(a,b) and P2(c,d) to be two points on a 2D plane.

  • a happens to equal the minimum value in Northern Latitude (LAT_N in STATION).
  • b happens to equal the minimum value in Western Longitude (LONG_W in STATION).
  • c happens to equal the maximum value in Northern Latitude (LAT_N in STATION).
  • d happens to equal the maximum value in Western Longitude (LONG_W in STATION).

Query the Manhattan Distance between points P1 and P2 and round it to a scale of 4 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.

 

더보기

[ 참고 : Manhattan distance ]

정의:  The distance between two points measured along axes at right angles. In a plane with p1 at (x1, y1)

        and p2 at (x2, y2), it is |x1 - x2| + |y1 - y2|.


2. 답

SELECT ROUND(ABS(MIN(lat_n) - MAX(lat_n)) + ABS(MIN(long_w) - MAX(long_w)) , 4)
FROM station

3. KEY POINT

 

  • ROUND(컬럼명/값, n) : 값을 소수점 이하 n자릿수로 반올림
  • ABS(컬럼명/값) : 값의 절댓값을 반환
  • MAX(컬럼명), MIN(컬럼명) : 해당 컬럼에서의 최댓값과 최솟값

 

www.hackerrank.com/challenges/weather-observation-station-18/problem?h_r=internal-search

 

Weather Observation Station 18 | HackerRank

Query the Manhattan Distance between two points, round or truncate to 4 decimal digits.

www.hackerrank.com

 

댓글