再添加两组案例条件,看看这是否有助于优化..
我需要优化case语句,因为它太长了..我在查询中有1500行和类似case语句。我刚刚选择了一组查询进行优化
select
case when ((
lower (id) like '%hol%'
or lower (campaign_name) like '%hol%'
or lower (marketing_source_code) like '%hol%'
or lower (call_to_action) like '%hol%'
or lower(program_type) like '%hol%'
or lower (campaign_lvl1_name) like '%hol%'
or lower (campaign_lvl2_name) like '%hol%'
or lower (campaign_lvl3_name) like '%hol%'
or lower (campaign_lvl4_name) like '%hol%'
)
and not (position ('HOLLYWOOD' in upper(campaign_name)) > 0 or
position ('HOLE' in upper(campaign_name)) > 0 or
position ('HOLDER' in upper(campaign_name)) > 0 or
position ('STOCKHOLM' in upper(campaign_name)) > 0 or
position ('HOLIDAY' in upper(campaign_name)) > 0 or
position ('CATHOLIC' in upper(campaign_name)) > 0 or
position ('HOLISTIC' in upper(campaign_name)) > 0 or
position ('HOLY' in upper(campaign_name)) > 0 or
position ('HOLTKAMP' in upper(campaign_name)) > 0 or
position ('HOLDING' in upper(campaign_name)) > 0 or
position ('CUSTHOLRECP' in upper(campaign_name)) > 0
)
and ( position('VSOM' in upper(campaign_name) ) > 0
or position('VSPHERE WITH OPERATIONS MANAGEMENT' in upper(campaign_name)) > 0
or position('VSOM' in upper(products) ) > 0
or position('VSPHERE WITH OPERATIONS MANAGEMENT' in upper(products)) > 0
))
then 1 else 0 end as vsom_hol_response,
case when ((
lower (campaign_name) like '%seminar%'
or lower (marketing_source_code) like '%seminar%'
or lower (call_to_action) like '%seminar%'
or lower (program_type) like '%seminar%'
or lower (campaign_lvl1_name) like '%seminar%'
or lower (campaign_lvl2_name) like '%seminar%'
or lower (campaign_lvl3_name) like '%seminar%'
or lower (campaign_lvl4_name) like '%seminar%'
)
and ( position('VSOM' in upper(campaign_name) ) > 0
or position('VSPHERE WITH OPERATIONS MANAGEMENT' in upper(campaign_name)) > 0
or position('VSOM' in upper(products) ) > 0
or position('VSPHERE WITH OPERATIONS MANAGEMENT' in upper(products)) > 0
))
then 1 else 0 end as vsom_seminar_response,
case when ((
lower (id) like '%webinar%'
or lower (campaign_name) like '%webinar%'
or lower (marketing_source_code) like '%webinar%'
or lower (call_to_action) like '%webinar%'
or lower (program_type) like '%webinar%'
or lower (campaign_lvl1_name) like '%webinar%'
or lower (campaign_lvl2_name) like '%webinar%'
or lower (campaign_lvl3_name) like '%webinar%'
or lower (campaign_lvl4_name) like '%webinar%'
)
and (
position('VSOM' in upper(campaign_name) ) > 0
or position('VSPHERE WITH OPERATIONS MANAGEMENT' in upper(campaign_name)) > 0
or position('VSOM' in upper(products) ) > 0
or position('VSPHERE WITH OPERATIONS MANAGEMENT' in upper(products)) > 0)
)
then 1 else 0 end as vsom_webinar_response
from base.vdim_campaign