Hive SQL逻辑-语句时的情况

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

我的查询:

case 
   when upper(a.camp_name) like "%Event%" and (upper(a.camp_name) not like "%Event-WBR%" or upper(a.camp_name) not like "%Event-Webinar%") THEN "Field"
   else "Demand"
end as Tactic

所需的输出:

Event-WBR = Demand
Event = Field

实际输出:

Event-WBR = Field
Event = Field
sql hive hiveql case-statement hive-query
1个回答
0
投票

尝试一下

case 
   when a.camp_name like '%Event' 
   then 'Field'
   when ((a.camp_name) like '%Event-WBR' or (a.camp_name) like '%Event-Webinar')
   then 'Demand'
end as Tactic

您也可以尝试以下方法

case 
   when (a.camp_name) = 'Event' 
   then 'Field'
   when (a.camp_name) in ('Event-WBR', 'Event-Webinar')
   then 'Demand'
end as Tactic
© www.soinside.com 2019 - 2024. All rights reserved.