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:
Field | Type |
ID | NUMBER |
NAME | VARCHAR2(17) |
COUNTRYCODE | VARCHAR2(3) |
DISTRICT | VARCHAR2(20) |
POPULATION | NUMBER |
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;
Wow! At last I got a website from where I be capable of actually take useful data regarding my study and knowledge. Karoline Gaby Deirdra