2017-02-14 104 views
0

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

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

這是兩個關鍵字中的任何一個還是全部?如果它是任何的話,那麼這是[** PostgreSQL通配符LIKE對於任何單詞列表**]的副本(http://stackoverflow.com/q/4928054/479863)。如果是全部,那麼這是[** RAILS/POSTGRESQL **中的多個LIKE和AND運算符](http://stackoverflow.com/q/42124181/479863)的重複。 –

回答

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

text_string ilike'%food%'and text_string ilike'%delivery%'then'Impacting'or text_string ilike'%food%'or text_string ilike'%delivery%'then'Impacting' –