Skip to content

Instantly share code, notes, and snippets.

@erhaem
Last active October 13, 2025 15:22
Show Gist options
  • Select an option

  • Save erhaem/08decafcdaf166a386f15367b7cc8c38 to your computer and use it in GitHub Desktop.

Select an option

Save erhaem/08decafcdaf166a386f15367b7cc8c38 to your computer and use it in GitHub Desktop.
Weather Observation Station hackerrank
SELECT DISTINCT city
FROM station
WHERE city REGEXP '^[^aeiouAEIOU]'
or city REGEXP '[^aeiouAEIOU]$';
-- select bagian atas: nyarii yang paling pendek
(select city, length(city)
from station
where length(city) = (
select min(length(city)) from station
)
order by city asc
limit 1)
union all -- buat nyatuin statement select yg atas dan bawah ini
-- select bagian atas: nyarii yang paling panjang
(select city, length(city)
from station
where length(city) = (
select max(length(city)) from station
) -- >> nyari nama city yang paling panjang
order by city asc -- kalo nemu banyak, urutin secara alfabet [abcdef-wxyz]
limit 1 -- dari banyak data, pilih 1 aja
)
/*
Output:
Amo 3
Marine On Saint Croix 21
*/
select distinct city
from station
/*where city like 'a%'
or city like 'i%'
or city like 'u%'
or city like 'e%'
or city like 'o%';*/
where city REGEXP '^[aeiouAEIOU]' -- til, ternyata bisa pake regex
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment