Summary
Summary of Weather Observation Station SQL Problem
In this tutorial, the speaker discusses solving a SQL problem related to the "Weather Observation Station 10" challenge on HackerRank. The task involves querying a table named station
with the following columns: ID
, city
, state
, lat_n
, and lon_w
. The goal is to retrieve city names that do not end with a vowel and eliminate any duplicate city names.
Steps to Solve the Problem
-
Initial Query: The speaker starts by selecting all data from the
station
table to visualize it:SELECT * FROM station;
-
Identifying Vowels: The vowels to avoid at the end of city names are:
a
,e
,i
,o
,u
. -
Constructing the Query:
- Using
LIKE
, the condition for city names not ending with vowels is constructed:SELECT DISTINCT city FROM station WHERE city NOT LIKE '%a' AND city NOT LIKE '%e' AND city NOT LIKE '%i' AND city NOT LIKE '%o' AND city NOT LIKE '%u';
- Using
-
Using Regular Expressions:
- The speaker explains a more concise way to achieve the same result using regular expressions:
SELECT DISTINCT city FROM station WHERE city NOT REGEXP '[aeiou]$';
- The speaker explains a more concise way to achieve the same result using regular expressions:
-
Alternative Regex Approach:
- Another method using the negation inside the pattern:
SELECT DISTINCT city FROM station WHERE city REGEXP '^[^aeiou].*';
- Another method using the negation inside the pattern:
Conclusion
The tutorial concludes by showcasing different methods to query city names that do not end with vowels, demonstrating both SQL LIKE
clauses and regular expressions for brevity and efficiency.