Solution to HackerRank SQL Practice Questions

Notebook
Feb 26, 2023

--

HackerRank SQL Question 18

Difficulty Level — Easy to Medium

Question: Query the Western Longitude (LONG_W)where the smallest Northern Latitude (LAT_N) in STATION is greater than . Round your answer to decimal places.

Input Format

The STATION table is described as follows:

— -

Solution 1: Using ROUND, WHERE, ORDER BY, LIMIT, and ‘>’ in SQL Server

SELECT ROUND(LONG_W, 4) FROM STATION
WHERE LAT_N > 38.7780 ORDER BY LAT_N ASC LIMIT 1
Using ROUND, WHERE, ORDER BY, LIMIT, and ‘>’ in SQL Server
Using ROUND, WHERE, ORDER BY, LIMIT, and ‘>’ in SQL Server

— -

Solution 2: Using SUB-QUERY, ROUND, WHERE, MIN, and ‘>’ in SQL Server

SELECT ROUND(LONG_W, 4) FROM STATION
WHERE
LAT_N = (SELECT MIN(LAT_N) FROM STATION WHERE LAT_N>38.7780)
Using SUB-QUERY, ROUND, WHERE, MIN, and ‘>’ in SQL Server
Using SUB-QUERY, ROUND, WHERE, MIN, and ‘>’ in SQL Server

— -

Note — All these codes have been tested against HackerRank’s MySQL Interface and might not work in other interfaces such as that of Oracle or DB2.

--

--