SQL查询以查找不以元音开头的城市名称列表

时间:2016-04-14 21:59:34

标签: mysql

我正在尝试从表格中查询CITY名称列表 - STATION不以元音开头,结果不能包含重复项。 该表只有id,city,population

这是我写的查询

SELECT DISTINCT CITY FROM STATION 
WHERE CITY RLIKE '[^bcdfghjklmnpqrstvwxyzBCDFGHJKLMNPQRSTVWXYZ].*';

这给出了错误的答案。我在这里做错了什么?

26 个答案:

答案 0 :(得分:15)

试试这个。

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

答案 1 :(得分:8)

正则表达式中的^具有不同的含义,具体取决于其位置。当它是正则表达式中的第一个字符时,它指的是字符串的开头。但是,如果它是集合中的第一个字符,例如[^abc],则表示not one of。当它出现在其他地方时,它只是引用^本身。

所以你需要这样的东西:

SELECT DISTINCT CITY FROM STATION 
WHERE CITY RLIKE '^[bcdfghjklmnpqrstvwxyzBCDFGHJKLMNPQRSTVWXYZ].*';

或者,只需排除您不想要的字母:

SELECT DISTINCT CITY FROM STATION 
WHERE CITY RLIKE '^[^aeiouAEIOU].*';

答案 2 :(得分:3)

查询来自STATION的CITY名称列表,这些名称不是以元音开头,也不是以元音结尾。在ORACLE

select distinct city 
from station 
where regexp_like(city, '^[^aeiouAEIOU]|*[^aeiouAEIOU]$');

在MySQL中 -

 select distinct city 
 from station 
 where city RLIKE '^[^aeiouAEIOU].*' OR 
 city RLIKE '^.*[^aeiouAEIOU]$';

答案 3 :(得分:2)

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%';

答案 4 :(得分:2)

尝试以下方法:

SELECT DISTINCT CITY FROM STATION
WHERE CITY REGEXP '^[^aeiou].*';

MySQL参考:https://dev.mysql.com/doc/refman/5.5/en/regexp.html

答案 5 :(得分:1)

尝试一下:

SELECT DISTINCT CITY 
FROM STATION 
WHERE CITY NOT REGEXP '[aeiouAEIOU]$'

答案 6 :(得分:1)

我尝试过这个。

An error occurred: @Output deleteMeeting not initialized in 'MeetingItemComponent'.

答案 7 :(得分:1)

我们可以使用Mysql。

select distinct city from station where city regexp '^[^aeiou].*';

To Know More About MySQL Regular Expression

对于Oracle,我们可以使用

select distinct(city) from station where regexp_like (city, '^[^AEIOU](*)');

To Know More About Oracle Regular Expression

对于MS SQL Server

select distinct city from station where city not like '[aeuio]%';

答案 8 :(得分:1)

没有正则表达式的简单示例

SELECT DISTINCT 
    City 
FROM Station
WHERE LEFT(City, 1) NOT IN ("a", "e", "i", "o", "u");

答案 9 :(得分:1)

select distinct city from station where city regexp
'^[^aeiou].*[^aeiou]$'

如果您的查询没有以元音开头和结尾。

答案 10 :(得分:0)

select DISTINCT CITY from STATION where CITY NOT LIKE '[a,e,i,o,u]%'

答案 11 :(得分:0)

select distinct city from station where REGEXP_LIKE(LOWER(city),'^[^aeiou].*.[^aeiou]$');

[^ aeiou]不接受aeiou。

答案 12 :(得分:0)

SELECT DISTINCT city FROM station
WHERE CITY NOT REGEXP '^[aeiou]'

MySQL接受了答案。

答案 13 :(得分:0)

select distinct <COLUMN NAME> from <table name>
WHERE SUBSTRING(<COLUMN NAME>,1,1) not in ('a','e','i','o','u','A','E','I','O','U')
order by <COLUMN NAME>

不同的单词不是以元音开头的。

答案 14 :(得分:0)

我曾为此工作

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%'

答案 15 :(得分:0)

这适用于MS SQL SERVER:

select distinct city from station where city NOT like '[aeuio]%' Order by City;

答案 16 :(得分:0)

在MS SQL中:

plt.xticks(x.astype(float), my_xticks)

答案 17 :(得分:0)

select distinct city from station where city regexp '^[^aeiou].*[^aeiou]$'

与众不同:,以避免在以下列上重复

regexp: MySql函数(regexp)获得正则表达式。表达式以^开头,以$结尾。在Oracle中,其regexp_like (city,'RegEx') Regular Expressions With Oracle Database

[^...]表示任何字符都不包含...中的任何字符
[^...].表示单个字符不包含...中的任何一个
[^...].*表示第一个字符不包含...中的任何一个
[^...].*[^...]表示第一个字符不包含...中的任何一个且不以...结尾
[^aeiou].*[^aeiou]表示第一个字符不是以元音开头,也不以元音结尾

答案 18 :(得分:0)

在ORACLE中:

select 
distinct(city)
from station
where regexp_like (city, '^[^A|E|I|O|U](*)');

此解决方案中无需指定结尾字母。出现的问题中不要求这样做。

答案 19 :(得分:0)

select distinct city from station where (
    left(city,1) not in ('a','e','i','o','u') 
    and  
    right(city,1) not in ('a','e','i','o','u')
);

答案 20 :(得分:0)

 SELECT DISTINCT city from STATION
 WHERE city NOT LIKE "[aieuo]%[aieuo] [aieuo]%[aieuo]"
 AND city NOT LIKE "[aieuo]%[aieuo]";

第一个NOT LIKE表示两个单词的城市名称中的每个单词都不以元音开头和结尾。第二个NOT LIKE是用于单字城市名称。

答案 21 :(得分:0)

您可以使用:

select distinct city from station where city  not RLIKE '^[aeiouAEIOU]'

答案 22 :(得分:0)

for oracle

select distinct 
    city 
from station 
where regexp_like(city, '^[^aeiouAEIOU].*');

答案 23 :(得分:0)

Select Distinct City from Station where City Like '[^aeiou]%';

MS SQL Server已测试。

答案 24 :(得分:0)

试试这个:

SELECT DISTINCT CITY FROM STATION WHERE
LOWER(SUBSTR(CITY,LENGTH(CITY),1)) IN ('a','e','i','o','u');

答案 25 :(得分:-1)

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%"
));

我想这会有用。