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

[HackerRank] Population Density Difference / Weather Observation Station 11 / Weather Observation Station 13

by MINNI_ 2021. 3. 23.

1) Population Density Difference


1. 문제

 

Query the difference between the maximum and minimum populations inCITY.

 

Input Format

The CITY table is described as follows:


2. 답

SELECT MAX(population) - MIN(population)
FROM city

3. KEY POINT

 

  • MAX(컬럼명) : 해당 컬럼에서의 최댓값
  • MIN(컬럼명) : 해당 컬럼에서의 최솟값

 

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

 

Population Density Difference | HackerRank

Query the difference between the maximum and minimum city populations in CITY.

www.hackerrank.com


 

2) Weather Observation Station 11


1. 문제

 

Query the list of CITY names from STATION that either do not start with vowels or do not end with vowels. Your result cannot contain duplicates.

 

Input Format

The STATION table is described as follows:

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


2. 답

SELECT DISTINCT(city)
FROM station
WHERE LEFT(city, 1) NOT IN ('A', 'E', 'I', 'O', 'U')
      OR RIGHT(city, 1) NOT IN ('A', 'E', 'I', 'O', 'U')

3. KEY POINT

 

  • LEFT(컬럼명, n) : 해당 컬럼의 문자열 중에 왼쪽부터 n번째 글자 추출
  • RIGHT(컬럼명, n) : 해당 컬럼의 문자열 중에 오른쪽부터 n번째 글자 추출
  • 컬럼명 IN (값) : 해당 컬럼 안에 특정 값들이 들어있는 글자 추출

 

 

 

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

 

Weather Observation Station 11 | HackerRank

Query a list of CITY names not starting or ending with vowels.

www.hackerrank.com

 

 


 

3) Weather Observation Station 13


1. 문제

 

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.

 

Input Format

The STATION table is described as follows:

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


2. 답

SELECT TRUNCATE(SUM(lat_n), 4)
FROM station
WHERE lat_n > 38.7880 AND lat_n < 137.2345

3. KEY POINT

 

  • TRUNCATE(컬럼명/값, n) : 값을 소수점 이하 n자릿수까지만 남기고 나머지 버림

 

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

 

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

댓글