Notice
Recent Posts
Recent Comments
Link
forest_moon
해커랭크 MYSQL 본문
초급문제 정리하기 !
CITY 테이블에 대한 내용은 다음과 같다.
01 모든 도시의 모든 컬럼 조회
Query all columns (attributes) for every row in the CITY table.
The CITY table is described as follows:
SELECT
*
FROM
CITY
;
02 특정 ID의 도시 조회
Query all columns for a city in CITY with the ID 1661.
The CITY table is described as follows:
SELECT
*
FROM
city
WHERE
id = 1661
;
03 특정 인구수를 넘는 미국내 도시 조회
Query the NAME field for all American cities in the CITY table with populations larger than 120000. The CountryCode for America is USA.
The CITY table is described as follows:
SELECT
name
FROM
city
WHERE
countrycode = 'USA'
AND
population > 120000;
04 일본의 모든 도시 이름 조회
Query the names of all the Japanese cities in the CITY table. The COUNTRYCODE for Japan is JPN.
The CITY table is described as follows:
SELECT
name
FROM
city
WHERE
countrycode = 'JPN'
05 인구수가 특정 값을 넘는 도시의 개수
Query a count of the number of cities in CITY having a Population larger than .
Input Format
The CITY table is described as follows:
SELECT
COUNT(*)
FROM
city
WHERE
population > 100000;
06 모든 도시의 평균 인구수
Query the average population for all cities in CITY, rounded down to the nearest integer.
Input Format
The CITY table is described as follows:
SELECT
ROUND(AVG(population), 0)
FROM
city
;
07 캘리포니아에 속한 모든 도시의 총 인구수
Query the total population of all cities in CITY where District is California.
Input Format
The CITY table is described as follows:
SELECT
SUM(population)
FROM
city
WHERE
district = 'California' ;
** 모든 도시의 총 인구수에서 문제를 잘못보고 처음에
SELECT population
FROM city
WHERE countrycode = 'California' 로 했는데 뭔가 이상하다 했는데 'district' 를 잘못해석함ㅎ..ㅎ
08 캘리포니아에 속한 모든 도시의 평균 인구수
Query the average population of all cities in CITY where District is California.
Input Format
The CITY table is described as follows:
SELECT
ROUND(AVG(population),0)
FROM
city
WHERE
district = 'California' ;
요거는 6번이랑 같은 맥락!
해커랭크에서 문제 풀어보는게 나름 재미있네