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 —2

--

Problem 1

Query a list of CITY and STATE from the STATION table.
The STATION table is described as follows:

Figure 1. Station table

Where LAT_N is the northern latitude and LONG_W is the western longitude.

Query

SELECT CITY, STATE
FROM STATION

Output

Acme LA 
Addison MI
Agency MO
Aguanga CA
Alanson MI
Alba MI
Albany CA
Albion IN
Algonac MI
Aliso Viejo CA
Allerton IA
Alpine AR
Alton MO
Amazonia MO
Amo IN
Andersonville GA
Andover CT
Anthony KS
Archie MO
Arispe IA {-truncated-}

Problem 2

Query a list of CITY names from STATION for cities that have an even ID number. Print the results in any order, but exclude duplicates from the answer.

Query

SELECT DISTINCT CITY
FROM STATION
WHERE MOD(ID, 2) = 0

Output

Aguanga 
Alba
Albany
Amo
Andersonville
Archie
Athens
Atlantic Mine
Bainbridge
Baker
Bass Harbor
Bayville
Beaufort
Bellevue
Benedict
Bennington
Bentonville
Biggsville
Bison
Bono {-truncated-}

Problem 3

Find the difference between the total number of CITY entries in the table and the…

--

--

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