SQL通配符搜索问题

时间:2017-06-20 14:30:47

标签: sql sql-server tsql wildcard

这是' Hackerrank'

中的问题
  

"查询STATION(表)中没有的CITY(列)名称列表   从元音开始,不要以元音结尾。你的结果不行   包含重复项。"

以下是我的回答,但我在Hackerrank中收到错误。我错过了一些非常愚蠢的东西吗?

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

4 个答案:

答案 0 :(得分:0)

打破它......

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

答案 1 :(得分:0)

我会说开始和结束关闭括号aswel

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

答案 2 :(得分:0)

这有效:

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

答案 3 :(得分:-1)

从上面的查询中删除空间,这将完美地工作

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