나는 이렇게 학습한다/Algorithm & SQL

On the Canadian Border (SQL for Beginners #2)

daco2020 2022. 6. 2. 23:18
반응형

You are a border guard sitting on the Canadian border. You were given a list of travelers who have arrived at your gate today. You know that American, Mexican, and Canadian citizens don't need visas, so they can just continue their trips. You don't need to check their passports for visas! You only need to check the passports of citizens of all other countries!

Select names, and countries of origin of all the travelers, excluding anyone from Canada, Mexico, or The US.

travelers table schema

  • name
  • country

NOTE: The United States is written as 'USA' in the table.

NOTE: Your solution should use pure SQL. Ruby is used within the test cases just to validate your answer.

 

 

Solution:

SELECT 
    * 
FROM 
    travelers 
WHERE 
    country not in ('Canada','Mexico','USA')

 

Result:

name country
Andrew Italy
Maria Spain
Jolie France
Jonathan Egypt
Mena Argentina
Lukas China

 

 

 

반응형

'나는 이렇게 학습한다 > Algorithm & SQL' 카테고리의 다른 글

SQL Grasshopper: Select Columns  (0) 2022.06.05
Remove String Spaces  (0) 2022.06.04
Easy SQL: Bit Length  (0) 2022.06.02
Easy SQL: ASCII Converter  (0) 2022.05.31
Easy SQL: Rounding Decimals  (0) 2022.05.30