SQL query to check if a name begins and ends with a vowel

后端 未结 25 916
臣服心动
臣服心动 2020-11-30 23:16

I want to query the list of CITY names from the table STATION(id, city, longitude, latitude) which have vowels as both their first and last charact

相关标签:
25条回答
  • 2020-12-01 00:12

    My simple solution :::

    SELECT DISTINCT CITY

    FROM STATION

    WHERE CITY LIKE '[a,e,i,o,u]%[a,e,i,o,u]';

    0 讨论(0)
  • 2020-12-01 00:13

    You can use LEFT() and RIGHT() functions. Left(CITY,1) will get the first character of CITY from left. Right(CITY,1) will get the first character of CITY from right (last character of CITY).

    DISTINCT is used to remove duplicates. To make the comparison case-insensitive, we will use the LOWER() function.

    SELECT DISTINCT CITY
    FROM STATION
    WHERE LOWER(LEFT(CITY,1)) IN ('a', 'e', 'i', 'o', 'u') AND
          LOWER(RIGHT(CITY,1)) IN ('a', 'e', 'i', 'o', 'u')
    
    0 讨论(0)
  • 2020-12-01 00:13

    Try this for beginning with vowel

    Oracle:

    select distinct *field* from *tablename* where SUBSTR(*sort field*,1,1) IN('A','E','I','O','U') Order by *Sort Field*;
    
    0 讨论(0)
  • 2020-12-01 00:14
    Select distinct(city) from station where city RLIKE '^[aeiouAEIOU]'
    

    Very simple answer.

    0 讨论(0)
  • 2020-12-01 00:15

    You could use a regular expression:

    SELECT DISTINCT city
    FROM   station
    WHERE  city RLIKE '^[aeiouAEIOU].*[aeiouAEIOU]$'
    
    0 讨论(0)
  • 2020-12-01 00:15

    For MS access or MYSQL server

    SELECT city FROM station
    WHERE City LIKE '[aeiou]%'and City LIKE '%[aeiou]';
    
    0 讨论(0)
提交回复
热议问题