HackerRank Easy SQL Challenges

Below are my solutions to all Easy SQL challenges on HackerRank.


1) Revising the Select Query I

Question

Screen Shot 2021-01-13 at 1.35.05 PM.png

Solution

MySQL / MS SQL Server / Oracle / DB2

Screen Shot 2021-01-13 at 9.59.04 PM.png

Output

Screen Shot 2021-01-13 at 10.00.01 PM.png


2) Revising the Select Query II

Question

Screen Shot 2021-01-13 at 1.41.01 PM.png

Solution

MySQL / MS SQL Server / Oracle / DB2

Screen Shot 2021-01-13 at 10.13.27 PM.png

Output

Screen Shot 2021-01-13 at 10.14.10 PM.png


3) Select All

Question

Screen Shot 2021-01-13 at 1.59.04 PM.png

Solution

MySQL / MS SQL Server / Oracle / DB2

Screen Shot 2021-01-13 at 10.15.20 PM.png

Output

Screen Shot 2021-01-13 at 10.15.49 PM.png


4) Select By ID

Question

Screen Shot 2021-01-13 at 2.01.15 PM.png

Solution

MySQL / MS SQL Server / Oracle / DB2

Screen Shot 2021-01-13 at 10.16.56 PM.png

Output

Screen Shot 2021-01-13 at 10.17.32 PM.png


5) Japanese Cities' Attributes

Question

Screen Shot 2021-01-13 at 2.03.12 PM.png

Solution

MySQL / MS SQL Server / Oracle / DB2

Screen Shot 2021-01-13 at 10.22.00 PM.png

Output

Screen Shot 2021-01-13 at 10.22.30 PM.png


6) Japanese Cities' Names

Question

Screen Shot 2021-01-13 at 2.05.07 PM.png

Solution

MySQL / MS SQL Server / Oracle / DB2

Screen Shot 2021-01-13 at 10.23.03 PM.png

Output

Screen Shot 2021-01-13 at 10.23.34 PM.png


7) Weather Observation Station 1

Question

Screen Shot 2021-01-13 at 2.06.40 PM.png

Solution

MySQL / MS SQL Server / Oracle / DB2

Screen Shot 2021-01-13 at 10.24.14 PM.png

Output

Screen Shot 2021-01-13 at 10.24.57 PM.png


8) Weather Observation Station 3

Question

Screen Shot 2021-01-13 at 2.09.16 PM.png

Solution

MySQL / MS SQL Server

Screen Shot 2021-01-13 at 10.25.33 PM.png

Output

Screen Shot 2021-01-13 at 10.26.15 PM.png


9) Weather Observation Station 4

Question

Screen Shot 2021-01-13 at 2.12.05 PM.png

Solution

MySQL / MS SQL Server / Oracle / DB2

Screen Shot 2021-01-13 at 10.26.46 PM.png

Output

Screen Shot 2021-01-13 at 10.27.20 PM.png


10) Weather Observation Station 5

Question

Screen Shot 2021-01-13 at 2.14.06 PM.png

Solution

MySQL / DB2

Screen Shot 2021-01-13 at 10.27.54 PM.png

Output

Screen Shot 2021-01-13 at 10.28.24 PM.png


11) Weather Observation Station 6

Question

Screen Shot 2021-01-13 at 2.30.38 PM.png

Solution

MySQL / MS SQL Server

Screen Shot 2021-01-13 at 10.29.06 PM.png

Output

Screen Shot 2021-01-13 at 10.31.59 PM.png


12) Weather Observation Station 7

Question

Screen Shot 2021-01-13 at 2.40.23 PM.png

Solution

MySQL / MS SQL Server / DB2

Screen Shot 2021-01-13 at 10.45.18 PM.png

Output

Screen%20Shot%202021-01-13%20at%2010.46.18%20PM.png


13) Weather Observation Station 8

Question

Screen Shot 2021-01-13 at 2.43.39 PM.png

Solution

MySQL / MS SQL Server

Screen%20Shot%202021-01-13%20at%2010.46.56%20PM.png

Output

Screen%20Shot%202021-01-13%20at%2010.47.26%20PM.png


14) Weather Observation Station 9

Question

Screen Shot 2021-01-13 at 2.45.56 PM.png

Solution

MySQL / MS SQL Server

Screen%20Shot%202021-01-13%20at%2010.47.59%20PM.png

Output

Screen%20Shot%202021-01-13%20at%2010.48.28%20PM.png


15) Weather Observation Station 10

Question

Screen Shot 2021-01-13 at 2.48.10 PM.png

Solution

MySQL / MS SQL Server / DB2

Screen%20Shot%202021-01-13%20at%2010.49.09%20PM.png

Output

Screen%20Shot%202021-01-13%20at%2010.49.39%20PM.png


16) Weather Observation Station 11

Question

Screen Shot 2021-01-13 at 2.50.25 PM.png

Solution

MySQL / MS SQL Server

Screen%20Shot%202021-01-13%20at%2010.50.09%20PM.png

Output

Screen%20Shot%202021-01-13%20at%2010.50.30%20PM.png


17) Weather Observation Station 12

Question

Screen Shot 2021-01-13 at 2.53.00 PM.png

Solution

MySQL / MS SQL Server

Screen%20Shot%202021-01-13%20at%2010.54.47%20PM.png

Output

Screen%20Shot%202021-01-13%20at%2010.55.24%20PM.png


18) Higher Than 75 Marks

Question

Screen Shot 2021-01-13 at 2.55.00 PM.png

Solution

MySQL / MS SQL Server / DB2

Screen%20Shot%202021-01-13%20at%2010.55.53%20PM.png

Output

Screen%20Shot%202021-01-13%20at%2010.56.13%20PM.png


19) Employee Names

Question

Screen Shot 2021-01-13 at 2.58.04 PM.png

Solution

MySQL / MS SQL Server / Oracle / DB2

Screen%20Shot%202021-01-13%20at%2010.56.43%20PM.png

Output

Screen%20Shot%202021-01-13%20at%2010.57.19%20PM.png


20) Employee Salaries

Question

Screen Shot 2021-01-13 at 3.00.35 PM.png

Solution

MySQL / MS SQL Server / Oracle / DB2

Screen%20Shot%202021-01-13%20at%2010.57.45%20PM.png

Output

Screen%20Shot%202021-01-13%20at%2010.58.08%20PM.png


21) Type of Triangle

Question

Screen Shot 2021-01-13 at 3.04.51 PM.png

Solution

MySQL / MS SQL Server / Oracle / DB2

Screen%20Shot%202021-01-13%20at%2010.58.28%20PM.png

Output

Screen%20Shot%202021-01-13%20at%2010.58.46%20PM.png


22) Revising Aggregations - The Count Function

Question

Screen Shot 2021-01-13 at 3.21.03 PM.png

Solution

MySQL / MS SQL Server / Oracle / DB2

Screen%20Shot%202021-01-13%20at%2010.59.06%20PM.png

Output

Screen%20Shot%202021-01-13%20at%2010.59.30%20PM.png


23) Revising Aggregations - The Sum Function

Question

Screen Shot 2021-01-13 at 3.23.15 PM.png

Solution

MySQL / MS SQL Server / Oracle / DB2

Screen%20Shot%202021-01-13%20at%2010.59.56%20PM.png

Output

Screen%20Shot%202021-01-13%20at%2011.00.16%20PM.png


24) Revising Aggregations - Averages

Question

Screen Shot 2021-01-13 at 3.25.18 PM.png

Solution

MySQL / MS SQL Server / Oracle / DB2

Screen%20Shot%202021-01-13%20at%2011.00.41%20PM.png

Output

Screen%20Shot%202021-01-13%20at%2011.01.01%20PM.png


25) Average Population

Question

Screen Shot 2021-01-13 at 3.27.14 PM.png

Solution

MySQL / MS SQL Server / Oracle / DB2

Screen%20Shot%202021-01-13%20at%2011.01.27%20PM.png

Output

Screen%20Shot%202021-01-13%20at%2011.01.40%20PM.png


26) Japan Population

Question

Screen Shot 2021-01-13 at 3.29.12 PM.png

Solution

MySQL / MS SQL Server / Oracle / DB2

Screen%20Shot%202021-01-13%20at%2011.02.13%20PM.png

Output

Screen%20Shot%202021-01-13%20at%2011.02.21%20PM.png


27) Population Density Difference

Question

Screen Shot 2021-01-13 at 3.31.14 PM.png

Solution

MySQL / MS SQL Server / Oracle / DB2

Screen%20Shot%202021-01-13%20at%2011.02.47%20PM.png

Output

Screen%20Shot%202021-01-13%20at%2011.03.10%20PM.png


28) The Blunder

Question

Screen%20Shot%202021-01-13%20at%2011.05.32%20PM.png

Screen%20Shot%202021-01-13%20at%2011.05.44%20PM.png

Solution

MySQL

Screen%20Shot%202021-01-13%20at%2011.07.26%20PM.png

Output

Screen%20Shot%202021-01-13%20at%2011.07.51%20PM.png


29) Top Earners

Question

Screen%20Shot%202021-01-13%20at%2011.08.59%20PM.png

Screen%20Shot%202021-01-13%20at%2011.09.11%20PM.png

Solution

MySQL / MS SQL Server / Oracle / DB2

SELECT MAX(salary * months), COUNT(salary) FROM Employee WHERE salary * months = (SELECT MAX(salary * months) FROM Employee);

Output

Screen%20Shot%202021-01-13%20at%2011.12.36%20PM.png


30) Weather Observation Station 2

Question

Screen Shot 2021-01-13 at 3.49.14 PM.png

Solution

MySQL / Oracle

Screen%20Shot%202021-01-13%20at%2011.13.22%20PM.png

Output

Screen%20Shot%202021-01-13%20at%2011.13.33%20PM.png


31) Weather Observation Station 13

Question

Screen Shot 2021-01-13 at 4.15.53 PM.png

Solution

MySQL / Oracle

Screen%20Shot%202021-01-13%20at%2011.14.05%20PM.png

Output

Screen%20Shot%202021-01-13%20at%2011.14.14%20PM.png


32) Weather Observation Station 14

Question

Screen Shot 2021-01-13 at 4.15.10 PM.png

Solution

MySQL

Screen%20Shot%202021-01-13%20at%2011.14.44%20PM.png

Output

Screen%20Shot%202021-01-13%20at%2011.15.08%20PM.png


33) Weather Observation Station 15

Question

Screen Shot 2021-01-13 at 4.14.25 PM.png

Solution

MySQL

Screen%20Shot%202021-01-13%20at%2011.15.28%20PM.png

Output

Screen%20Shot%202021-01-13%20at%2011.15.37%20PM.png


34) Weather Observation Station 16

Question

Screen Shot 2021-01-13 at 4.13.37 PM.png

Solution

MySQL / Oracle

Screen%20Shot%202021-01-13%20at%2011.16.15%20PM.png

Output

Screen%20Shot%202021-01-13%20at%2011.16.25%20PM.png


35) Weather Observation Station 17

Question

Screen Shot 2021-01-13 at 4.12.42 PM.png

Solution

MySQL

Screen%20Shot%202021-01-13%20at%2011.17.04%20PM.png

Output

Screen%20Shot%202021-01-13%20at%2011.17.13%20PM.png


36) Asian Population

Question

Screen Shot 2021-01-13 at 4.11.16 PM.png

Solution

MySQL / MS SQL Server / Oracle

Screen%20Shot%202021-01-13%20at%2011.17.44%20PM.png

Output

Screen%20Shot%202021-01-13%20at%2011.17.54%20PM.png


37) African Cities

Question

Screen Shot 2021-01-13 at 4.20.18 PM.png

Solution

MySQL / MS SQL Server / Oracle

Screen%20Shot%202021-01-13%20at%2011.18.30%20PM.png

Output

Screen%20Shot%202021-01-13%20at%2011.18.38%20PM.png


38) Average Population of Each Continent

Question

Screen Shot 2021-01-13 at 4.22.26 PM.png

Solution

MySQL / MS SQL Server / Oracle

Screen%20Shot%202021-01-13%20at%2011.19.17%20PM.png

Output

Screen%20Shot%202021-01-13%20at%2011.19.24%20PM.png


39) Draw the Triangle 1

Question

Screen Shot 2021-01-13 at 5.50.18 PM.png

Solution

MS SQL Server

Screen%20Shot%202021-01-13%20at%2011.19.53%20PM.png

Output

Screen%20Shot%202021-01-13%20at%2011.20.04%20PM.png


40) Draw the Triangle 2

Question

Screen Shot 2021-01-13 at 5.59.09 PM.png

Solution

MS SQL Server

Screen%20Shot%202021-01-13%20at%2011.20.33%20PM.png

Output

Screen%20Shot%202021-01-13%20at%2011.20.44%20PM.png


In [1]:
! jupyter nbconvert --to html HackerRank_Easy_SQL_Challenges_Screenshots.ipynb
[NbConvertApp] Converting notebook HackerRank_Easy_SQL_Challenges.ipynb to html
[NbConvertApp] Writing 9794282 bytes to HackerRank_Easy_SQL_Challenges.html
In [ ]: