Weather Observation Station 5
Weather Observation Station 5
+ 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.
+ 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;
+ 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
+ 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 :)
+ 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;
Sort 3926 Discussions, By:
Please Login in order to post a comment