We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • Hackerrank Home
  • Prepare
    NEW
  • Certify
  • Compete
  • Career Fair
  • Hiring developers?
  1. Prepare
  2. SQL
  3. Aggregation
  4. Weather Observation Station 15
  5. Discussions

Weather Observation Station 15

Problem
Submissions
Leaderboard
Discussions

Sort 1051 Discussions, By:

votes

Please Login in order to post a comment

  • MAHelaly
    7 years ago+ 11 comments

    Note to the respected moderators: the problem statement is not clear at all and is quite confusing.

    631|
    Permalink
    View more Comments..
  • rohitnk
    6 years ago+ 3 comments

    MySql: Select round(long_w,4) from Station where lat_n < 137.2345 order by lat_n desc limit 1;

    52|
    Permalink
  • RodneyShag
    5 years ago+ 6 comments

    MySQL solution

    From my HackerRank solutions.

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

    Let me know if you have any questions.

    30|
    Permalink
    View more Comments..
  • lelcat
    4 years ago+ 1 comment

    Using Oracle...
    Most of the answers listed in this discussion have answers like this:

    // Solution1 -- order by desc and select top
    select * from 
      (select round(LONG_W,4) from STATION
        where LAT_N<137.2345
        order by LAT_N desc) 
     where rownum=1;
    

    Is there anything worse about this pattern? I would have thought ordering was more resource intensive than assigning a variable and seeking. Is there a reason not to do this?

    // Solution 2 -- assign max_lat_n variable and seek
    variable max_lat_n number;
    exec select max(LAT_N) into :max_lat_n from STATION where LAT_N<137.2345;
    select round(LONG_W,4) from STATION where LAT_N=:max_lat_n;
    


    And does this subquery approach repeat the max() operation on every row?

    // Solution 3 -- subquery the max() operation
    select round(LONG_W,4) from STATION
      where LAT_N=(select max(LAT_N) from STATION
                     where LAT_N<137.2345);
    
    11|
    Permalink
  • joramkabiruc
    5 years ago+ 0 comments

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

    9|
    Permalink
Load more conversations

Need Help?


View top submissions
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy
  • Request a Feature