SQL - 如何选择单词末尾具有某些值的单词

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15324012/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 14:11:03  来源:igfitidea点击:

SQL - how to select words with certain values at the end of word

sqlselect

提问by DRastislav

iam new to sql and i would like to know how can I find the letter or symbol at the end of value in column called Name? E.g if i would find something i will write select * from 'table' where 'Name' like '%es%'but it will find me all rows contains es
Lets say - lesl, pespe, mess... but how to write select which will select just values with 'es'At the end of word? ... using regexi will use es\Z..... thanks in advance!

我是 sql 的新手,我想知道如何在名为的列中找到值末尾的字母或符号Name?例如,如果我想找到的东西我会写select * from 'table' where 'Name' like '%es%',但它会找到我的所有行包含es
比方说- lesl, pespe, mess...但如何写选择将选择只值 'es'在单词的结尾?...使用regex我将使用 es\Z..... 提前致谢!

回答by John Woo

You have to remove the last %, so it will only select words endingwith es.

您必须删除最后一个%,因此它只会选择以.结尾的单词es

select * from table where Name like '%es'

回答by NDJ

You're currently matching on: ..where 'Name' like '%es%'.

您目前正在匹配: ..where 'Name' like '%es%'

Which equates to anything, then 'es' then anything else.

这相当于anything, then 'es' then anything else.

Removing the last %changes the where to anything then 'es'.

删除最后一个会%更改到 的位置 anything then 'es'

in short.. you need ..where 'Name' like '%es'

总之..你需要 ..where 'Name' like '%es'

回答by runa

The query ..where 'Name' like '%es' will find columns where name ends with "ES". But if we need to find column where name ends with either "E" or "S", the query would be

查询 ..where 'Name' like '%es' 将查找名称以“ES”结尾的列。但是如果我们需要找到名称以“E”或“S”结尾的列,查询将是

.. where 'Name' LIKE '%[ES]'

.. where 'Name' LIKE '%[ES]'

回答by Sarath Baiju

  1. if you want to find name start with something like 'test' use => select name from table where name like 'test%'.
  2. if you want to find name end with something like 'test' use => select name from table where name like '%test'.
  3. if you want to find name start with s and end with h use => select name from table where name like 's%'and name like '%h' or simply select name from table where name like 's%h'.
  1. 如果您想查找以“test”之类的名称开头的名称,请使用 => 从表中选择名称,其中名称类似于“test%”。
  2. 如果您想找到以“test”之类的名称结尾的名称,请使用 => select name from table where name like '%test'。
  3. 如果您想查找以 s 开头并以 h 结尾的名称,请使用 => select name from table where name like 's%'and name like '%h' 或者简单地从 table where name like 's%h' 中选择名称。

回答by ABHISHEK GUPTA

You can also use REGEX

您也可以使用正则表达式

select distinct city from station where city REGEXP '[aeiou]$';

Resources: To Know more about REGEXP

资源:了解有关 REGEXP 的更多信息