SQL 如何检索以特定字符开头和结尾的行?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5788879/
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
How to retrieve rows that begin and end with specific characters?
提问by jaleel
I have one table called STUDENT. In this table there are two columns, ID and NAME. I want to retrieve all rows from this table where name starts with 'ab' and ends with 'k'. What is the SQL query for doing this?
我有一张叫做 STUDENT 的桌子。在这个表中有两列,ID 和 NAME。我想从该表中检索名称以“ab”开头并以“k”结尾的所有行。执行此操作的 SQL 查询是什么?
回答by pconcepcion
I think you are looking for something like:
我认为您正在寻找类似的东西:
SELECT ID, NAME FROM STUDENT WHERE NAME LIKE 'ab%k';
For wildcard operationsyou should use a WHERE
clause with the LIKEkeyword that allows you to filter columns that match a given patternusing the %
symbol as a wildcard.
对于通配符操作,您应该使用WHERE
带有LIKE关键字的子句,该子句允许您使用符号作为通配符过滤与给定模式匹配的列%
。
There is a question about the List of special characters for SQL LIKE clausethat has a good list of LIKE
special characters
有一个关于SQL LIKE 子句的特殊字符列表的问题,它有一个很好的特殊字符列表LIKE
回答by Kodamasimham
select ID, Name from student where name like 'ab%%k'
回答by Hanif Khan
its like if you are looking for find name start with H and end with F just write query.
就像如果您正在寻找以 H 开头并以 F 结尾的查找名称,只需编写查询。
select emp_name from employee_test where emp_name like 'H%F';