【问题标题】:SQLite query to match text string in columnSQLite 查询以匹配列中的文本字符串
【发布时间】:2013-04-16 09:29:12
【问题描述】:

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

Audi,Ford,Chevy,BMW,Toyota

我想生成一个与字符串“BMW”匹配的任何列的查询。如何在 SQL 中做到这一点?

【问题讨论】:

    标签: sql sqlite


    【解决方案1】:

    您可以使用通配符:%

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

    【讨论】:

    • 如果我想拉“奥迪”和“宝马”,我该怎么做?
    • 应该是:select * from table where name like '%BMW%' or name like '%audi%'
    【解决方案2】:

    我认为您正在寻找类似的东西

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

    % 是 LIKE 语句的通配符。

    更多信息可以找到HERE

    【讨论】:

      【解决方案3】:
      select * from table where name like '%BMW%'
      

      【讨论】:

        【解决方案4】:

        另一种方式...

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

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2018-04-09
          • 1970-01-01
          • 1970-01-01
          • 2018-03-15
          • 2018-03-15
          • 1970-01-01
          • 2021-12-17
          相关资源
          最近更新 更多