Weather Observation Station 15 in SQL | HackerRank Solution

Hello coders, today we are going to solve Weather Observation Station 15 HackerRank Solution in SQL.

Weather Observation Station 15

Problem

Query the Western Longitude (LONG_W) for the largest Northern Latitude (LAT_N) in STATION that is less than 137.2345. Round your answer to 4 decimal places.

Input Format

The STATION table is described as follows:

FieldType
IDNUMBER
CITYVARCHAR2(21)
STATEVARCHAR2(2)
LAT_NNUMBER
Long_WNUMBER
STATION

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

Solution – Weather Observation Station 15 in SQL

MySQL

select round(long_w, 4) from station 
where lat_n = (select max(lat_n) 
from station where lat_n < 137.2345);

Disclaimer: The above Problem (Weather Observation Station 15) is generated by Hacker Rank but the Solution is Provided by CodingBroz. This tutorial is only for Educational and Learning Purpose.

4 thoughts on “Weather Observation Station 15 in SQL | HackerRank Solution”

  1. select substr(round(long_w, 4),1,8) from station
    where lat_n = (select max(lat_n)
    from station where lat_n < 137.2345);

  2. select substr(round(long_w, 4),1,8) from station
    where lat_n = (select max(lat_n)
    from station where lat_n < 137.2345);

  3. correct query:

    select cast(round(long_w,4) as decimal(10,4)) from station
    where lat_n = (select max(lat_n) from station where lat_n < 137.2345);

  4. FOR MS SQL SERVER:
    SELECT TOP 1 CONVERT(DECIMAL(15,4),LONG_W) FROM STATION WHERE LAT_N<137.2345 ORDER BY LAT_N DESC

Leave a Comment

Your email address will not be published. Required fields are marked *