[hive]case 语句中字符串匹配

  当使用case when时,有时会需要对某个字段做子串匹配。如果是在where条件中,我们会直接使用 like '%xx%'来匹配,但case when语句不行

 

  这时需要使用instr函数

 

  examples:

 

  

case when instr(study, '语文') > 0 then 0
when instr(study, '数学') > 0 then 1
when instr(study, '英语') > 0 then 2
else 3
end

 

posted @ 2018-11-15 16:57  爱斯特拉冈  阅读(5011)  评论(0编辑  收藏  举报