🍰
LEARNING BY DOING
  • Home
  • Skills
    • SQL
      • Leetcode
        • 177. Nth Highest Salary
        • 175. Combine Two Tables
        • 178. Rank Scores
      • Hackerrank
        • Easy
          • The Blunder
          • Top Earners
          • Weather Observation Station 2
          • Weather Observation Station 13
          • Weather Observation Station 14
          • Weather Observation Station 15
          • Weather Observation Station 16
          • Weather Observation Station 17
          • Asian Population
          • Draw The Triangle 1
          • Draw The Triangle 2
        • Medium
          • Weather Observation Station 18
          • Weather Observation Station 19
          • Weather Observation Station 20
          • Ollivander's Inventory
          • Challenges
          • Contest Leaderboard
  • Company Research
    • Google
      • Google Search
      • Youtube
      • Google Ads
Powered by GitBook
On this page
  • Analysis
  • Note:
  • Query
  1. Skills
  2. SQL
  3. Hackerrank
  4. Easy

Weather Observation Station 15

PreviousWeather Observation Station 14NextWeather Observation Station 16

Last updated 4 years ago

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

Input Format

The STATION table is described as follows:

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

Analysis

This question asks for the longitude of the largest latitude in station table having latitude less than 137.2345. We will have the table

  • select round(long_w, 4)

  • from station

  • where lat_n = (select max(lat_n) from station where lat_n < 137.2345 ORDER BY LAT_N DESC )

Note:

when using max, the order of the table is not important; when suing limit, the order of the list will matter as the limit/top select from the top of the list

Query

/*QUERY 1*/
SELECT ROUND(LONG_W, 4) FROM STATION WHERE LAT_N = (SELECT MAX(LAT_N) FROM STATION WHERE LAT_N < 137.2345)

/*QUERY 2*/
SELECT ROUND(LONG_W, 4) FROM STATION WHERE LAT_N < 137.2345 ORDER BY LAT_N DESC LIMIT 1;