Write a SQL query to get all cities that don't start with vowels and don't end with vowels from the STATION table using LOWER(), LENGTH() and SUBSTRING() function NOT IN and AND operators. This is the solution of HackerRank's Weather Observation Station 12 SQL problem.
Table name: STATION
Table Structure:
Fileds | Type |
ID | NUMBER |
CITY | VARCHAR |
STATE | VARCHAR |
LAT_N | NUMBER |
LONG_W | NUMBER |
SQL Query:
SELECT DISTINCT CITY
FROM STATION
WHERE LOWER(SUBSTRING(CITY, LENGTH(CITY), 1)) NOT IN ('a', 'e', 'i', 'o', 'u')
AND LOWER(SUBSTRING(CITY, 1, 1)) NOT IN ('a', 'e', 'i', 'o', 'u')