AI Mind

Learn, explore, or build the future of AI with top stories on the latest trends, tools, and…

Follow publication

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:

Figure 1. City table

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

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Published in AI Mind

Learn, explore, or build the future of AI with top stories on the latest trends, tools, and technology. Share your crazy success stories or AI-fueled fails in a supportive community.

No responses yet

Write a response