HackerRank – Revising the Select Query II

HackerRank SQL Problem 2 – Difficulty: Easy

Learn SQL by solving problem #2

I am going to analyze the HackerRank #2 challenge for SQL in this post. You can find all of these problems in the SQL Problems category. If you are just familiar with the basic concepts of SQL, you can improve your skill by solving these problems.

Problem 2

Query the names of all American cities in CITY with populations larger than 120000. The CountryCode for America is the USA.

Input format

The CITY table is described as follows:

FieldType
IDNUMBER
NAMEVARCHAR2(17)
COUNTRYCODEVARCHAR2(3)
DISTRICTVARCHAR2(20)
POPULATIONNUMBER

Examination

“Query the names” can translate into: SELECT NAME

“in CITY table” can translate into: FROM CITY

“populations larger than 120000” can translate into: POPULATION > 120000

“CountryCode for America is USA” can translate into: COUNTRYCODE = ‘USA’

So “American cities with populations larger than 120000” leads to: WHERE COUNTRYCODE = ‘USA’ AND POPULATION > 120000

Code

The final solution can be as follows:

SELECT NAME FROM CITY WHERE COUNTRYCODE = 'USA' AND POPULATION > 120000;

13 thoughts on “HackerRank – Revising the Select Query II

Leave a Reply

Your email address will not be published. Required fields are marked *