SQL Server 2014 Word Count

前端 未结 4 1492
温柔的废话
温柔的废话 2021-01-07 14:17

I have a SQL Server database that I\'m searching for keywords.

All I need to know is how many of the keywords appear in a column.

For example



        
4条回答
  •  春和景丽
    2021-01-07 14:51

    Try this one

    WITH C(txt) AS(
      SELECT 'I like red shoes but not blue'
      UNION
      SELECT 'I like red shoes and green shoes, but green are my favourite'
    )
    SELECT COUNT(txt)
    FROM C WHERE txt LIKE '%green%'
    OR txt LIKE '%blue%'
    OR txt LIKE '%red%'
    

提交回复
热议问题