Diana
Diana

Reputation: 1

SQL: Grouping Multiple Conditions

Is it possible to group multiple conditions to pull different data from different date ranges? I'd like to pull different marketing campaign performance data that were running at different times.

e.g. having two or more where clauses as in the following hypothetical query:


select
a.click_date,
b.account_id,
b.campaign_name,
sum(click_cnt) as clicks,
from A as a 
full join B as b
on a.C = b.D and a.E = b.F
where 
(
 a.click_date >= '02-04-2018' and a.click_date <= '02-10-2018' 
and 
 b.campaign_name = '%ad1%'
and
 b.account_id in ('10001') 
)
or 
where 
(
 a.click_date >= '02-11-2018' and a.click_date <= '02-15-2018' 
and 
 b.campaign_name = '%ad2%'
and
 b.account_id in ('10002') 
)    
group by 1, 2, 3

Upvotes: 0

Views: 71

Answers (0)

Related Questions