我正在尝试查询表格中的CITY名称列表 - STATION,这些名称不以元音开头,结果不能包含重复项.表只有id,城市,人口
这是我写的查询
SELECT DISTINCT CITY FROM STATION
WHERE CITY RLIKE '[^bcdfghjklmnpqrstvwxyzBCDFGHJKLMNPQRSTVWXYZ].*';
Run Code Online (Sandbox Code Playgroud)
这给出了错误的答案.我在这做错了什么?
Tin*_*ran 19
试试这个.
SELECT DISTINCT CITY
FROM STATION
WHERE CITY NOT RLIKE '^[aeiouAEIOU].*$'
Run Code Online (Sandbox Code Playgroud)
^正则表达式中的A 可以具有不同的含义,具体取决于其位置.当它是正则表达式中的第一个字符时,它指的是字符串的开头.但是当它是一组中的第一个角色时,就像[^abc]它一样not one of.当它出现在其他地方时,它只是指^自己.
所以你需要这样的东西:
SELECT DISTINCT CITY FROM STATION
WHERE CITY RLIKE '^[bcdfghjklmnpqrstvwxyzBCDFGHJKLMNPQRSTVWXYZ].*';
Run Code Online (Sandbox Code Playgroud)
或者,只是排除你不想要的字母:
SELECT DISTINCT CITY FROM STATION
WHERE CITY RLIKE '^[^aeiouAEIOU].*';
Run Code Online (Sandbox Code Playgroud)
小智 6
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%';
Run Code Online (Sandbox Code Playgroud)
小智 6
STATION查询不以元音开头或不以元音结尾的 CITY 名称列表。在甲骨文中
select distinct city
from station
where regexp_like(city, '^[^aeiouAEIOU]|*[^aeiouAEIOU]$');
Run Code Online (Sandbox Code Playgroud)
在 MySQL 中 -
select distinct city
from station
where city RLIKE '^[^aeiouAEIOU].*' OR
city RLIKE '^.*[^aeiouAEIOU]$';
Run Code Online (Sandbox Code Playgroud)