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 12

PreviousWeather Observation Station 11NextHigher Than 75 Marks

Last updated 1 year ago

Query the list of CITY names from STATION that do not start with vowels and do not end with vowels. Your result cannot contain duplicates.

Sol:

select distinct city from station where not city regexp '^[aeoiu]' and not city regexp '[aeiou]$'

Explanation:

This query retrieves distinct city names from the STATION table where the city name does not start with a vowel ('a', 'e', 'o', 'i', or 'u') and does not end with a vowel.

  • NOT CITY REGEXP '^[aeoiu]': This condition in the WHERE clause checks if the CITY column does not match the pattern defined by the regular expression.

    • ^[aeoiu]: This part of the regular expression matches city names that start with any of the vowels 'a', 'e', 'o', 'i', or 'u'.

    • NOT: This negates the condition, selecting city names that do not match the defined pattern at the beginning of the city name.

  • NOT CITY REGEXP '[aeiou]$': This condition in the WHERE clause checks if the CITY column does not match the pattern defined by the regular expression.

    • [aeiou]$: This part of the regular expression matches city names that end with any of the vowels 'a', 'e', 'o', 'i', or 'u'.

    • NOT: This negates the condition, selecting city names that do not match the defined pattern at the end of the city name.

So, the query selects cities where the city name neither starts nor ends with a vowel.

Weather Observation Station 12 | HackerRankHackerRank
Logo