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. Basic Select
  4. Weather Observation Station 5
  5. Discussions

Weather Observation Station 5

Problem
Submissions
Leaderboard
Discussions

Sort 3926 Discussions, By:

votes

Please Login in order to post a comment

  • andrewstuart
    7 years ago+ 36 comments

    This question needs to be rewritten for clarity. "the possible minimum value" is completely unclear and doesn't give any idea as to the scope of the question. The shortest city name in the table is my best guess, but it shouldn't be a guessing game.

    In fact, this question is so unclear and contrived I really think it should be removed.

    348|
    Permalink
    View more Comments..
  • rishaba
    5 years ago+ 109 comments

    My SQL Version:

    select city, length(city) from station
    order by length(city),city asc
    limit 1;
    select city, length(city) from station
    order by length(city) desc
    limit 1;
    
    311|
    Permalink
    View more Comments..
  • LeCodeManiac
    7 years ago+ 3 comments

    Please instead of compiler just saying wrong answer as a reason it should show us the expected output, it gives us more clues when the question isn't explanatory enough

    206|
    Permalink
  • marinskiy
    4 years ago+ 35 comments

    Here is Oracle solution from my HackerrankPractice repository:

    SELECT *
    FROM
        (SELECT CITY, LENGTH(CITY)
        FROM STATION
        ORDER BY LENGTH(CITY), CITY)
    WHERE ROWNUM = 1
    UNION
    SELECT *
    FROM
        (SELECT CITY, LENGTH(CITY)
        FROM STATION
        ORDER BY LENGTH(CITY) DESC, CITY)
    WHERE ROWNUM = 1;
    

    Feel free to ask if you have any questions :)

    152|
    Permalink
    View more Comments..
  • AlexiVossos
    7 years ago+ 14 comments

    Answer in MS SQL SERVER:

    SELECT TOP 1 CITY, LEN(CITY) FROM STATION ORDER BY LEN(CITY),CITY; SELECT TOP 1 CITY, LEN(CITY) FROM STATION ORDER BY LEN(CITY) DESC,CITY;

    53|
    Permalink
    View more Comments..
Load more conversations

Need Help?


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