我正在运行以下SQL脚本来创建一个表格,其中包含哪些营销工作正在促使人们访问我的网站以填写表单。
营销源标记的案例声明不起作用。对于marketing_source列,我的搜索结果仍然具有搜索结果的值,而这些值现在应该只是“google-adwords”。
我也在2015年9月15日的创建日期以及之后我的过滤器明确指出createddate> ='1/1/2016'时获得了结果。
有什么想法吗?
create table temp.roi_inqs as (
Select
a.ID,
cast(a.createddate as date) as date,
CASE
WHEN a.marketing_source_stamp__c = 'search%' then 'google-adwords'
ELSE a.marketing_source_stamp__c
END AS marketing_source,
CASE
when a.contactid is null then b.email
when a.contactid is not null then c.email
end as prospect_email
from rjm_current.sf_campaignmember a
left join rjm_current.sf_lead b on b.id = a.leadid
left join rjm_current.sf_contact c on c.id = a.contactid
where cast(a.createddate as date) >= '1/1/2016'
AND (
campaign_marketing_type__c in ('A','C'))
OR
(campaign_marketing_type__c = 'B'
AND a.status in ('Registered','Attended','No Show')));
答案 0 :(得分:1)
您的整个谓词的格式为
A AND B OR C
如果你没有放任何括号,这意味着你要查询
(A AND B) OR C
当你真的打算写
时A AND (B OR C)
作为一般规则:如果您正在混合AND
和OR
答案 1 :(得分:0)
@Lukas Eder回答了我关于日期问题的问题。
对于案例陈述,我必须更改marketing_source_stamp__c =' search%' to marketing_source_stamp__c LIKE' search%'这个问题就解决了。
CASE
WHEN a.marketing_source_stamp__c LIKE 'search%' then 'google-adwords'
ELSE a.marketing_source_stamp__c
END AS marketing_source,