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.
SeLeCt t3.CITY,t3.l from
(
SELECT min(t.l) as 'min', max(t.l) as 'max' from
(select CITY, CHAR_LENGTH(CITY) as 'l' from STATION ORDER BY CHAR_LENGTH(CITY) ) t
) t2,
(select CITY, CHAR_LENGTH(CITY) as 'l' from STATION ORDER BY CHAR_LENGTH(CITY) ) t3
WhErE t2.min = t3.l limit 1
union all
SeLeCt t3.CITY,t3.l from
(
SELECT min(t.l) as 'min', max(t.l) as 'max' from
(select CITY, CHAR_LENGTH(CITY) as 'l' from STATION ORDER BY CHAR_LENGTH(CITY) ) t
) t2,
(select CITY, CHAR_LENGTH(CITY) as 'l' from STATION ORDER BY CHAR_LENGTH(CITY) ) t3
WhErE t2.max =t3.l
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Weather Observation Station 5
You are viewing a single comment's thread. Return to all comments →
Yes, you can do it in one statement:
SeLeCt t3.CITY,t3.l from ( SELECT min(t.l) as 'min', max(t.l) as 'max' from (select CITY, CHAR_LENGTH(CITY) as 'l' from STATION ORDER BY CHAR_LENGTH(CITY) ) t ) t2, (select CITY, CHAR_LENGTH(CITY) as 'l' from STATION ORDER BY CHAR_LENGTH(CITY) ) t3 WhErE t2.min = t3.l limit 1 union all SeLeCt t3.CITY,t3.l from ( SELECT min(t.l) as 'min', max(t.l) as 'max' from (select CITY, CHAR_LENGTH(CITY) as 'l' from STATION ORDER BY CHAR_LENGTH(CITY) ) t ) t2, (select CITY, CHAR_LENGTH(CITY) as 'l' from STATION ORDER BY CHAR_LENGTH(CITY) ) t3 WhErE t2.max =t3.l