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.
Weather Observation Station 8
Weather Observation Station 8
Sort by
recency
|
4105 Discussions
|
Please Login in order to post a comment
Following are the various approaches to solve the problem:
Approach - 1 (REGEXP)
SELECT DISTINCT CITY FROM STATION WHERE CITY REGEXP '^[aeiou]' AND CITY REGEXP '[aeiou]$'
Approach - 2 (SUBSTRING)
Method 1: SELECT DISTINCT CITY FROM STATION WHERE SUBSTRING(CITY, 1, 1) IN ('a', 'e', 'i', 'o', 'u') AND SUBSTRING(CITY, -1, 1) IN ('a', 'e', 'i', 'o', 'u')
Method 2: SELECT DISTINCT CITY FROM STATION WHERE SUBSTRING(CITY, 1, 1) IN ('a', 'e', 'i', 'o', 'u') AND SUBSTRING(CITY, LENGTH(CITY), 1) IN ('a', 'e', 'i', 'o', 'u')
Approach - 3 (LEFT & RIGHT FUNCTION)
SELECT DISTINCT CITY FROM STATION WHERE LEFT(CITY, 1) IN ('a', 'e', 'i', 'o', 'u') AND RIGHT(CITY, 1) IN ('a', 'e', 'i', 'o', 'u')
Approach - 4 (LIKE OPERATOR)
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%') AND (CITY LIKE '%a' OR CITY LIKE '%e' OR CITY LIKE '%i' OR CITY LIKE '%o' OR CITY LIKE '%u');
P.S. All above operators (IN, LIKE, REGEXP) used are case insensitive, so no need to write 'a' and 'A', simply 'a' will do the work for both the cases
Upvote if it helped :)
Why the left side letter is in lower case ,it should be uppr case .As the name of the city starts with upper case .
SELECT DISTINCT CITY FROM STATION WHERE LEFT(LOWER(CITY), 1) IN ('a', 'e', 'i', 'o', 'u') AND RIGHT(LOWER(CITY), 1) IN ('a', 'e', 'i', 'o', 'u');
this code works for MS SQl server
select distinct city from station where city like '[aeiou]%[aeiou]';
MySQL