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
2) Weather Observation Station 2
1. 문제
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.
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
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
'MySQL > 문제풀이' 카테고리의 다른 글
[HackerRank] Population Density Difference / Weather Observation Station 11 / Weather Observation Station 13 (0) | 2021.03.23 |
---|---|
[HackerRank] 여러 개의 INNER JOIN : New Companies (0) | 2021.03.22 |
[LeetCode] 175. Combine Two Tables (0) | 2021.03.22 |
[LeetCode] 182. Duplicate Emails (0) | 2021.03.22 |
[LeetCode] 620. Not Boring Movies (0) | 2021.03.22 |
댓글