Member-only story
HackerRank SQL Problems and Solutions — 1
Problem 1
Query all columns for all American cities in the CITY table with populations larger than 100000
. The CountryCode for America is USA
.
The CITY table is described as follows:

Query
SELECT *
FROM CITY
WHERE TRUE
AND COUNTRYCODE = 'USA'
AND POPULATION > 100000;
Output
3878 Scottsdale USA Arizona 202705
3965 Corona USA California 124966
3973 Concord USA California 121780
3977 Cedar Rapids USA Iowa 120758
3982 Coral Springs USA Florida 117549
Problem 2
Query the NAME field for all American cities in the CITY table with populations larger than 120000
. The CountryCode for America is USA
.
Query
SELECT NAME
FROM CITY
WHERE 0=0
AND COUNTRYCODE = 'USA'
AND POPULATION > 120000
Output
Scottsdale
Corona
Concord
Cedar Rapids
Problem 3
Query all columns (attributes) for every row in the CITY table.
Query
SELECT * FROM CITY
Output
6 Rotterdam NLD Zuid-Holland 593321
3878…