SQL 获取城市名称要么不以元音开头要么不以元音结尾

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/49228926/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 05:23:28  来源:igfitidea点击:

Get city name either do not start with vowels or do not end with vowels

sql

提问by Shanti

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

从 STATION 查询不以元音开头或不以元音结尾的城市名称列表。您的结果不能包含重复项。

Input Format

输入格式

The STATION table is described as follows:

STATION表描述如下:

enter image description here

在此处输入图片说明

I write the below query but works fine. Any suggestion?

我写了下面的查询,但工作正常。有什么建议吗?

SELECT DISTINCT city FROM station WHERE city NOT RLIKE '^[aeiouAEIOU].*[aeiouAEIOU]$';

SELECT DISTINCT city FROM station WHERE city NOT RLIKE '^[aeiouAEIOU].*[aeiouAEIOU]$';

采纳答案by Anand G

Assuming you are using MySQL, Here is what you are looking for

假设您使用的是 MySQL,这就是您要查找的内容

SELECT DISTINCT city FROM station WHERE city RLIKE '^[aeiouAEIOU].*[aeiouAEIOU]$'

SELECT DISTINCT city FROM station WHERE city RLIKE '^[aeiouAEIOU].*[aeiouAEIOU]$'

Footnote : RLIKEand DISTINCT

脚注:RLIKEDISTINCT

回答by Mina Samy

Try this:

尝试这个:

SELECT DISTINCT CITY FROM STATION WHERE CITY NOT RLIKE '^[aeiouAEIOU]' 
AND
CITY NOT RLIKE '[aeiouAEIOU]$'

回答by Vignesh VS

This SQL Query will helpful for you. If you are using MS SQL then follow this line of code given below:

此 SQL 查询将对您有所帮助。如果您使用的是 MS SQL,请按照下面给出的这行代码进行操作:

SELECT DISTINCT CITY 
FROM STATION  
WHERE CITY NOT LIKE '[AEIOU]%' OR CITY NOT LIKE '%[aeiou]';

If you are using MySQL then follow this line of code given below:

如果您使用的是 MySQL,请按照下面给出的这行代码进行操作:

SELECT DISTINCT CITY 
FROM STATION 
WHERE (CITY NOT IN (SELECT DISTINCT CITY FROM STATION WHERE CITY LIKE '%a' OR CITY LIKE '%e' OR CITY LIKE '%i' OR CITY LIKE '%o' OR CITY LIKE '%u'))
OR 
(CITY NOT IN (SELECT CITY FROM STATION WHERE CITY LIKE 'A%' OR CITY LIKE 'E%' OR CITY LIKE 'I%' OR CITY LIKE 'O%' OR CITY LIKE 'U%'));

回答by AB Abhi

This SQL Query will helpful for you if you are using Oracle:

如果您正在使用,此 SQL 查询将对您有所帮助Oracle

SELECT DISTINCT city
FROM station
WHERE regexp_like (city, '^[^aeiouAEIOU].*') 
OR regexp_like (city, '.*[^aeiouAEIOU]$');

Another answer if you are using Oracle:

如果您使用的是 Oracle,另一个答案是:

SELECT DISTINCT (CITY) 
FROM STATION 
WHERE NOT regexp_like(lower(CITY),'^[aeiou].*[aeiou]$');

回答by Samrat Rai

Try the following:

请尝试以下操作:

SELECT city 
FROM station 
WHERE left(city,1) not regexp 'a|e|i|o|u' or right(city,1) not regexp 'a|e|i|o|u' 
GROUP BY city

回答by Raj Singh

SELECT DISTINCT CITY FROM STATION WHERE CITY REGEXP '^[^aeiou]|[^aeiou]$';

this is what you are looking for bro.

这就是你要找的兄弟。

回答by rob111

 SELECT DISTINCT city FROM station WHERE city RLIKE '^[^aeiouAEIOU].* 
 [^aeiouAEIOU]$';

You have to place caret character inside square brackets which means not any vowels. Hereis explanation

您必须将插入字符放在方括号内,这意味着没有任何元音。是解释

回答by ebuzz168

SELECT DISTINCT city
FROM   station
WHERE  city REGEXP '^[^aeiouAEIOU]|[^aeiouAEIOU]$'

回答by vijay

Try this:

尝试这个:

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%')
OR (CITY NOT LIKE '%a' AND
    CITY  NOT LIKE '%e' AND
    CITY NOT LIKE '%i' AND 
    CITY NOT LIKE '%o' AND 
    CITY NOT LIKE '%u')

回答by nglauber

Oracle solution:

甲骨文解决方案:

SELECT DISTINCT CITY FROM STATION WHERE 
NOT REGEXP_LIKE(UPPER(CITY), '^[AEIOU]') OR 
NOT REGEXP_LIKE(UPPER(CITY), '[AEIOU]$');