匹配关键字的字符串

时间:2017-02-14 21:55:20

标签: postgresql text keyword matching sql-like

我有一个包含文本字符串的字段,例如:

Credit for an item
Credit for menu
Debit for food
Credit for food
Debit for Delivery
Etc.

我想将它们分为两类,影响调整而不影响调整

我试图在SQL中编写这个表达式:

If "Text_string" contain "Keywords: Food, Delivery", then "Impacting" else "None Impacting"

非常感谢

1 个答案:

答案 0 :(得分:0)

select  case
        when text_string ilike '%food%' and 
             text_string ilike '%delivery%' then 'Impacting'
        else 'None impacting'
        end as IsImpacting
from    YourTable