case-when语句

ekqde3dh  于 2021-06-25  发布在  Hive
关注(0)|答案(2)|浏览(499)

我的问题:

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
fjaof16o

fjaof16o1#

你可以用两个 when 学生:

(case when (upper(a.camp_name) not like "%Event-WBR%" or 
            upper(a.camp_name) not like "%Event-Webinar%"
           ) then 'Event'
      when upper(a.camp_name) like "%Event%" then 'Event'
      else 'Deman'
 end) as tactic
v1uwarro

v1uwarro2#

实际上你应该用and替换or

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

但这里还有另外两个选择:
如果你只想做“事件”这个词,你可以这样做

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 "Demand"
   else "Field"
end as Tactic

如果你只想排除这两个词,你可以这样做。

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

相关问题