获取城市名称要么不以元音开头,要么不以元音结尾

时间:2018-03-12 05:55:57

标签: sql

查询STATION的CITY名称列表,这些名称不是以元音开头,也不是以元音结尾。您的结果不能包含重复项。

输入格式

STATION表描述如下:

enter image description here

我写下面的查询,但没有正常工作。有什么建议吗?

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

42 个答案:

答案 0 :(得分:4)

SELECT DISTINCT city
FROM   station
WHERE  city REGEXP '^[^aeiouAEIOU]|[^aeiouAEIOU]$'

答案 1 :(得分:1)

SELECT DISTINCT CITY FROM STATION WHERE CITY REGEXP '^[^aeiou]|[^aeiou]$';

这就是您要寻找的兄弟。

答案 2 :(得分:1)

select distinct city from station where city not like '[aeiou]%' and city not like '%[aeiou]'

答案 3 :(得分:0)

由于提到了开始和结束不应为元音的要求,因此我们可以在RLIKE中使用模式:

从车站选择不同的城市,其中(left(city,1)不在('a','e','i','o','u')中,而right(city,1)不在(' a','e','i','o','u'));

答案 4 :(得分:0)

您可以尝试:

SELECT DISTINCT CITY 
FROM STATION
WHERE CITY REGEXP '^[^aeiou]|[^aeiou]$'

这里首先^使它检查第一个字符,并且内部[^aeiou]说不是以a,e,iu开头。和| [^aeiou]$也不以a,e,i,o,u结尾!

答案 5 :(得分:0)

假设您正在使用MySQL,那么您正在寻找

SELECT DISTINCT city FROM station WHERE city RLIKE '^[aeiouAEIOU].*[aeiouAEIOU]$'

脚注:RLIKEDISTINCT

答案 6 :(得分:0)

SELECT distinct city FROM station 
WHERE City not LIKE '[aeiou]%' and CITY NOT LIKE '%[aeiou]'

答案 7 :(得分:0)

假设您在黑客级别上看到了这个问题,并且给出了表STATION模式的屏幕快照,这也说明了同样的事情。这是我的答案,它在MYSQL中对我有用。

select DISTINCT(city) from STATION where CITY REGEXP '^[^aeiou]' or CITY REGEXP '.*[^aeiou]$';

答案 8 :(得分:0)

这个怎么样?

SELECT CITY from STATION WHERE LOWER(CITY) NOT REGEXP '^[aeiou].*[aeiou]$' GROUP BY CITY

答案 9 :(得分:0)

MySQL RLIKE运算符执行字符串表达式与模式的模式匹配。该模式作为参数提供。

SELECT DISTINCT city FROM station 
WHERE city NOT RLIKE '^[aeiouAEIOU].*[aeiouAEIOU]$';

参考: https://www.w3resource.com/mysql/string-functions/mysql-rlike-function.php https://dev.mysql.com/doc/refman/8.0/en/regexp.html#operator_regexp

答案 10 :(得分:0)

尝试一下:

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

答案 11 :(得分:0)

这将按照您想要的方式工作:

SELECT city 
FROM station 
WHERE left(city,1) not regexp 'a|e|i|o|u' or right(city,1) not regexp 'a|e|i|o|u' 
GROUP BY city

答案 12 :(得分:0)

mysql

“不要以元音开头或者不要以元音结尾”的答案是 从车站选择不同的城市 不是CITY RLIKE'^ [AEIOUaeiou]'或NOT CITY RLIKE'。* [AEIOUaeiou] $';

“不要以元音开始,而不要以元音结束”的答案是 从车站选择不同的城市 不是CITY RLIKE'^ [AEIOUaeiou]'而不是CITY RLIKE'。* [AEIOUaeiou] $';

答案 13 :(得分:0)

对于oracle,请尝试以下操作:

SELECT DISTINCT CITY FROM STATION WHERE REGEXP_LIKE(CITY,'^.*[^aeiouAEIOU]$') 
UNION 
SELECT DISTINCT CITY FROM STATION WHERE REGEXP_LIKE(CITY,'^[^aeiouAEIOU].*$');

答案 14 :(得分:0)

您的问题的解决方案应该是以下查询:

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

答案 15 :(得分:0)

SELECT DISTINCT CITY 
FROM STATION 
WHERE 
  SUBSTRING(CITY,1,1) NOT IN ('A','E','I','O','U') 
  OR 
  SUBSTRING(CITY,1,1) NOT IN ('a','e','i','o','u')

此代码适用于MS SQL SERVER。

答案 16 :(得分:0)

从车站选择其他城市,其中城市不喜欢'%a',城市不喜欢'%i' 和CITY不喜欢'%e'和CITY不喜欢'%o'和CITY不喜欢'%u';

答案 17 :(得分:0)

对于MySQL Select DISTINCT CITY from STATION where CITY REGEXP '^[^aeiou]|[^aeiou]$';

答案 18 :(得分:0)

对于甲骨文:select DISTINCT CITY FROM STATION WHERE REGEXP_LIKE(CITY,'^[^aeiou]|[^aeiou]$','i');

答案 19 :(得分:0)

简单的 MySql 查询可以是这样的:

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

答案 20 :(得分: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%')
OR (CITY NOT LIKE '%a' AND
    CITY  NOT LIKE '%e' AND
    CITY NOT LIKE '%i' AND 
    CITY NOT LIKE '%o' AND 
    CITY NOT LIKE '%u')

答案 21 :(得分:0)

此SQL查询对您有所帮助。 如果您使用的是MS SQL,请按照以下代码进行操作:

SELECT DISTINCT CITY 
FROM STATION  
WHERE CITY NOT LIKE '[AEIOU]%' OR CITY NOT LIKE '%[aeiou]';

如果您使用的是MySQL,请按照以下代码进行操作:

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'))
OR 
(CITY NOT IN (SELECT CITY FROM STATION WHERE CITY LIKE 'A%' OR CITY LIKE 'E%' OR CITY LIKE 'I%' OR CITY LIKE 'O%' OR CITY LIKE 'U%'));

答案 22 :(得分:0)

尝试以下操作:

SELECT city 
FROM station 
WHERE left(city,1) not regexp 'a|e|i|o|u' or right(city,1) not regexp 'a|e|i|o|u' 
GROUP BY city

答案 23 :(得分:0)

如果您使用的是var User = require('../models/user'); module.exports = function(app,express){ var api = express.Router(); api.post('/comment', function(req,res){ var user = new User({ name: req.body.name, comment: req.body.comment, date: req.body.date }); user.save(function(err){ if(err){ res.send(err); return; } res.json({ message: "User has commented"}); }); }); return api; } ,此SQL查询将对您有帮助:

Oracle

如果使用的是Oracle,另一个答案:

SELECT DISTINCT city
FROM station
WHERE regexp_like (city, '^[^aeiouAEIOU].*') 
OR regexp_like (city, '.*[^aeiouAEIOU]$');

答案 24 :(得分:0)

 SELECT DISTINCT city FROM station WHERE city RLIKE '^[^aeiouAEIOU].* 
 [^aeiouAEIOU]$';

您必须将尖号字符放在方括号内,这意味着没有任何元音。 Here是解释

答案 25 :(得分:0)

使用MS SQL对上述语句的纠正如下所示:

选择不同的城市 来自STATION
城市不喜欢'[aeiou]%'或城市不喜欢'[aeiou] ';

答案 26 :(得分: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%'
AND CITY NOT LIKE '%a' 
AND CITY NOT LIKE '%e'
AND CITY NOT LIKE '%i'
AND CITY NOT LIKE '%o'
AND CITY NOT LIKE '%u'

答案 27 :(得分:0)

选择不同的城市 来自STATION 在('a','e','i','o','u','A','E','I','O'中不在(CITY,Length(CITY),1)的位置,'U') 按城市订购

答案 28 :(得分:0)

选择不同        市 从        站 哪里        不在('a','e','i','o','u')中的Lower(Left(City,1))        或不在('a','e','i','o','u')中的Lower(Right(City,1))

答案 29 :(得分:0)

SELECT DISTINCT CITY 
FROM STATION 
WHERE 
left(city,1) NOT IN ('a','e','i','o','u') OR RIGHT(city,1) 

NOT IN ('a','e','i','o','u')

答案 30 :(得分:0)

这对我使用MYSQL有用。我还按城市对结果进行了分组,这不是必需的……更漂亮:

select distinct CITY
from STATION
where CITY NOT RLIKE '^[aeiouAEIOU]'
  OR CITY NOT RLIKE '[AEIOUaeiou]$'
GROUP BY CITY;

答案 31 :(得分:0)

这对我有用

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

答案 32 :(得分:0)

mySQL query:
SELECT DISTINCT CITY FROM STATION WHERE CITY REGEXP '^[^aeiou]' OR CITY REGEXP '[^aeiou]$' 

答案 33 :(得分:0)

Oracle解决方案:

SELECT DISTINCT CITY FROM STATION WHERE 
NOT REGEXP_LIKE(UPPER(CITY), '^[AEIOU]') OR 
NOT REGEXP_LIKE(UPPER(CITY), '[AEIOU]$'); 

答案 34 :(得分:0)

正确回答,

var header = {
        'Content-Type': 'multipart/form-data'
    }

await axios.post("/", fd,{ headers : header });

答案 35 :(得分:0)

EVALUATE(
    UNION (
        ROW ( "Plant Number", "All", "Plant Name", "<All Plants>" ),
        ALL ( 'PLANT PR1'[Plant Number], 'PLANT PR1'[Plant Name] )
    )
)
ORDER BY [Plant Name]

答案 36 :(得分:0)

mysql查询: SELECT DISTINCT city FROM station WHERE city NOT REGEXP '^[aeiouAEIOU].*[aeiouAEIOU]$';

答案 37 :(得分:0)

select distinct city
from station 
where not lower(substr(city,1,1)) in ('a','e','i','o','u')
      or not lower(substr(city,-1,1)) in ('a','e','i','o','u');

答案 38 :(得分:0)

以下查询应执行所需的操作。它对我成功了!

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

答案 39 :(得分:-1)

SELECT DISTINCT CITY 
FROM STATION 
WHERE SUBSTR(CITY,1,1) NOT IN ('A','E','I','O','U') OR
      SUBSTR(CITY,-1,1) NOT IN ('a','e','i','o','u');

答案 40 :(得分:-1)

MYSQL:

class

说明: 使用正则表达式和NOT条件。 因此,基本上是搜索以元音“ ^ [aeiou]”开头的城市,这些元音由“ n”之间的“ n”值连接。运算符和以元音“ [aeiou] $”结尾的第二个条件。 最后,由于应用了NOT条件,因此仅筛选出不符合条件的那些并显示出来。

答案 41 :(得分:-1)

在MySQL中,正则表达式与在Python中相同。

在这种情况下,您也可以使用正则表达式。

  1. 选择以元音开头和结尾的城市。
  2. 接下来,将放在前面,这将消除这些城市。

查询将是:

select distinct(city) from station where not (city rlike '^[aeiouAEIOU]' and city rlike '[aeiouAEIOU]$');