匹配关键字的字符串

问题描述 投票:0回答:1

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

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"

首先十分感谢

postgresql text keyword matching sql-like
1个回答
0
投票
select  case
        when text_string ilike '%food%' and 
             text_string ilike '%delivery%' then 'Impacting'
        else 'None impacting'
        end as IsImpacting
from    YourTable
© www.soinside.com 2019 - 2024. All rights reserved.