I get these Challenge on HackerRank
Write a query to print the list of CITY that start with vowels (a, e, i, o, u) in lexicographical order. Do not print duplicates.
My solution:
Select DISTINCT(City)
From Station
Where City like 'A%'
or City like 'E%'
or City like 'I%'
or City like 'O%'
or City like 'U%'
Order by City;
Other solution:
select distinct(city) from station
where upper(substr(city, 1,1)) in ('A','E','I','O','U');
This is very clever, but I want to know, if are there any other ways to solve this?
Any kind of DB is OK.
Regular expressions in MySQL / MariaDB:
select distinct city from station where city regexp '^[aeiouAEIOU]' order by city
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With