SQL SQLite 查询以匹配列中的文本字符串

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16033395/
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:50:35  来源:igfitidea点击:

SQLite query to match text string in column

sqlsqlite

提问by turtle

I have a database column that contains text in CSV format. A sample cell looks like this:

我有一个包含 CSV 格式文本的数据库列。示例单元格如下所示:

Audi,Ford,Chevy,BMW,Toyota

I'd like to generate a query that matches any column with the string 'BMW'. How can I do this in SQL?

我想生成一个与字符串“BMW”匹配的任何列的查询。如何在 SQL 中执行此操作?

回答by Vishal Suthar

You can use wildcard characters: %

您可以使用通配符: %

select * from table 
where name like '%BMW%'

回答by Xavjer

I think you are looking for something like

我想你正在寻找类似的东西

SELECT * FROM Table
WHERE Column LIKE '%BMW%'

the % are wildcards for the LIKE statement.

% 是 LIKE 语句的通配符。

More information can be found HERE

更多信息可以在这里找到

回答by Arif YILMAZ

select * from table where name like '%BMW%'

回答by Marimuthu Kandasamy

Another Way...

其它的办法...

--Create Table 2 :
Create Table #Table1
(
    Roll_No INT, 
    Student_Address Varchar(200)
)
Go

-- Insert Values into #Table1: 
Insert into #Table1 Values ('1','1st Street')
Insert into #Table1 Values ('2','2rd Street')
Insert into #Table1 Values ('3','3rd Street')
Insert into #Table1 Values ('4','4th Road')
Insert into #Table1 Values ('5','5th Street')
Insert into #Table1 Values ('6','6th Street')
Insert into #Table1 Values ('7','7th Street')
Insert into #Table1 Values ('8','8th Wing')

--Query
Select * from #Table1 where CharIndex('Street',Student_Address) > 0

--Clean Up:
Drop table #Table1