简体   繁体   English

SQL通配符搜索问题

[英]SQL Wildcard search issue

This is the question in 'Hackerrank' 这是“ Hackerrank”中的问题

"Query the list of CITY(Column) names from STATION(Table) that do not start with vowels and do not end with vowels. Your result cannot contain duplicates." “从STATION(表)查询不以元音开头也不以元音结尾的CITY(列)名称列表。您的结果不能包含重复项。”

Below is my answer, but I am getting an error in Hackerrank. 以下是我的答案,但我在Hackerrank中遇到错误。 Am I missing something that is very silly? 我是否错过了一些非常愚蠢的东西?

SELECT DISTINCT [City] FROM [Station] WHERE [City] NOT LIKE '[aeiou]%[aeiou]'

快分手...

[City] NOT LIKE '[aeiou]%' AND [City] NOT LIKE '%[aeiou]'

我会说脱掉开始和结束括号括号

[City] NOT LIKE 'aeiou%' AND [City] NOT LIKE '%aeiou'

This works: 这有效:

SELECT
  distinct (city)
FROM
  station
WHERE
  city not rlike '^[aeiouAEIOU].* $'
  AND city not rlike '^.* [aeiouAEIOU]$';

Remove space from above query, this will work perfectly 从上面的查询中删除空间,这将完美地工作

SELECT
  distinct (city)
FROM
  station
WHERE
  city not rlike '^[aeiouAEIOU].*$'
  AND city not rlike '^.*[aeiouAEIOU]$';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM