Pavithra's Space
  • Home
  • Skills
    • SQL
    • HackerRank
      • Revising the Select Query I
      • Revising the Select Query II
      • Select All
      • Select By ID
      • Japanese Cities' Attributes
      • Japanese Cities' Names
      • Weather Observation Station 1
      • Weather Observation Station 3
      • Weather Observation Station 4
      • Weather Observation Station 5
      • Weather Observation Station 6
      • Weather Observation Station 7
      • Weather Observation Station 8
      • Weather Observation Station 9
      • Weather Observation Station 10
      • Weather Observation Station 11
      • Weather Observation Station 12
      • Higher Than 75 Marks
      • Employee Names
      • Employee Salaries
Powered by GitBook
On this page
  1. Skills
  2. HackerRank

Weather Observation Station 8

PreviousWeather Observation Station 7NextWeather Observation Station 9

Last updated 1 year ago

Query the list of CITY names from STATION which have vowels (i.e., a, e, i, o, and u) as both their first and last characters. Your result cannot contain duplicates.

Sol:

SELECT DISTINCT CITY FROM STATION

WHERE CITY REGEXP '^[AEIOU]' AND CITY REGEXP '[AEIOU]$';

Explanation:

  • REGEXP '^[AEIOU]': This condition in the WHERE clause checks if the CITY column starts with any of the specified vowels using the regular expression pattern ^[AEIOU].

    • ^ denotes the start of the string.

    • [AEIOU] denotes a character class that matches any one character from the specified set of vowels ('A', 'E', 'I', 'O', 'U').

  • REGEXP '[AEIOU]$': This condition in the WHERE clause checks if the CITY column ends with any of the specified vowels using the regular expression pattern [AEIOU]$.

    • [AEIOU] denotes a character class that matches any one character from the specified set of vowels ('A', 'E', 'I', 'O', 'U').

    • $ denotes the end of the string.

So, the query selects cities where the city name both starts and ends with one of the specified vowels.

Weather Observation Station 8 | HackerRankHackerRank
Logo