해커랭크 African Cities 문제 바로가기 

 

<문제 해석>

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'

+ Recent posts