<문제 해석>
Given the CITY and COUNTRY tables, query the names of all cities where the CONTINENT is 'Africa'.
Note: CITY.CountryCode and COUNTRY.Code are matching key columns.
주어진 CITY, COUNTRY 테이블에서 CONTINENT가 'Africa'인 모든 도시이름이 나오는 쿼리를 입력
CITY테이블에서 CountryCode 와 Country테이블에서 Code가 매칭되는 컬럼.
Input Format
The CITY and COUNTRY tables are described as follows:


<문제 풀이>
WHERE 사용 풀이
1. 두 테이블을 매칭되는 countrycode로 조인
2. continent 가 'Africa'인 WHERE 조건문
3. name 컬럼이 두 테이블 모두 있기 때문에 도시이름이 적힌 city테이블의 name을 추출
SELECT city.name
FROM city
INNER JOIN country ON city.countrycode = country.code
WHERE country.continent = 'Africa'
AND 사용 풀이
1. 두 테이블을 country code와 continent = 'Africa' 기준으로 조인
2. name 컬럼이 두 테이블 모두 있기 때문에 도시이름이 적힌 city테이블의 name을 추출
SELECT city.name
FROM city
INNER JOIN country ON city.countrycode = country.code AND country.continent = 'Africa'
'SQL > MySQL 문제풀이' 카테고리의 다른 글
[SQL INNER JOIN][HackerRank] Average Population of Each Continent(해석/풀이) (0) | 2022.05.23 |
---|---|
[SQL INNER JOIN][HackerRank] Population Census (풀이/해석) (0) | 2022.05.23 |
[HackerRank] Weather Observation Station 18 Solution(해석/풀이) (0) | 2022.05.22 |
[HackerRank] Weather Observation Station 17 Solution(해석/풀이) (0) | 2022.05.22 |
[HackerRank] Weather Observation Station 13 Solution(해석/풀이) (0) | 2022.05.22 |