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
— -
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)
— -
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.