如何检索以特定字符开始和结束的行?

时间:2022-04-01 11:38:22

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?

我有一张叫学生的桌子。在该表中有两列,ID和NAME。我想从这个表中检索所有以ab开头以k结尾的行。这样做的SQL查询是什么?

3 个解决方案

#1


28  

I think you are looking for something like:

我认为你在寻找的是:

SELECT ID, NAME FROM STUDENT WHERE NAME LIKE 'ab%k';

For wildcard operations you should use a WHERE clause with the LIKE keyword that allows you to filter columns that match a given pattern using the %symbol as a wildcard.

对于通配符操作,您应该使用带有LIKE关键字的WHERE子句,该子句允许您使用%符号作为通配符来筛选匹配给定模式的列。

There is a question about the List of special characters for SQL LIKE clause that has a good list of LIKE special characters

有一个问题是关于SQL LIKE子句的特殊字符列表,它有一个很好的特殊字符列表

#2


3  

select ID, Name from student where name like 'ab%%k'

#3


1  

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';

#1


28  

I think you are looking for something like:

我认为你在寻找的是:

SELECT ID, NAME FROM STUDENT WHERE NAME LIKE 'ab%k';

For wildcard operations you should use a WHERE clause with the LIKE keyword that allows you to filter columns that match a given pattern using the %symbol as a wildcard.

对于通配符操作,您应该使用带有LIKE关键字的WHERE子句,该子句允许您使用%符号作为通配符来筛选匹配给定模式的列。

There is a question about the List of special characters for SQL LIKE clause that has a good list of LIKE special characters

有一个问题是关于SQL LIKE子句的特殊字符列表,它有一个很好的特殊字符列表

#2


3  

select ID, Name from student where name like 'ab%%k'

#3


1  

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';