HackerRank – Revising the Select Query I

HackerRank SQL Problem 1 – Difficulty: Easy

Learn SQL by solving problem #1

HackerRank has great problems that you can challenge yourself and solve them step by step. Attempting to solve these different types of SQL tests, can improve your ability, and general skill to use queries. We are going to solve these problems together. 1st problem has been analyzed in this post.

Problem 1

Query all columns for all American cities in CITY with populations larger than 100000. The CountryCode for America is USA.

Input format

The CITY table is described as follows:

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

Examination

“Query all columns” can translate into: SELECT *

“in CITY table” can translate into: FROM CITY

“population larger than 100000” can translate into: POPULATION > 100000

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

So “American cities with populations larger than 100000” leads to:

WHERE COUNTRYCODE = ‘USA’ AND POPULATION > 100000

Code

The final solution can be as follows:

SELECT * FROM CITY WHERE COUNTRYCODE = 'USA' AND POPULATION > 100000;

1 thought on “HackerRank – Revising the Select Query I

Leave a Reply

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