这是来自hackerrank的mysql
我的第一个查询运行得很好
select distinct city from station where city not regexp '^[aeiou]' and city not regexp '[aeiou]$'但是我的第二个问题给出了错误的答案
select distinct city from station where city not regexp '^[aeiouAEIOU].*[aeiouAEIOU]$'它正在编译,但给出了错误的结果
发布于 2019-06-13 16:43:59
https://dev.mysql.com/doc/refman/8.0/en/regexp.html
“'NOT”是对REGEXP的否定,
'REGEXP‘->检查'REGEXP’如果满足,则返回1,否则返回0
select 'Chelsea' REGEXP '^[aeiou].*[aeiou]$' ;
0‘'NOT’->检查'REGEXP‘,然后返回与结果相反的结果。
select 'Chelsea' not REGEXP '^[aeiou].*[aeiou]$' ;
1在本例中,'Chelsea‘不是以元音开头,因此REGEXP为0,not REGEXP为1。
因此,您计算的是城市,甚至名称都以元音开头或结尾。
发布于 2020-10-30 00:12:42
这在MS SQL server中有效:
SELECT DISTINCT city FROM station WHERE city NOT LIKE '[AEIOU]%' AND city NOT LIKE '%[aeiou]';发布于 2019-07-16 12:30:52
这对我使用RLIKE操作符很有效...希望这能有所帮助:
select distinct CITY from STATION where CITY NOT RLIKE '^[aeiouAEIOU]' AND CITY NOT RLIKE '[AEIOUaeiou]$' GROUP BY CITY;https://stackoverflow.com/questions/56575274
复制相似问题