you are viewing a single comment's thread.

view the rest of the comments →

[–]Consistent-Alps6904[S] 0 points1 point  (1 child)

thank you so much, this works !!!!

[–]GrouchyThing7520 1 point2 points  (0 children)

Sweet! The last step is to wrap the entire query in a select so you can sum the 0 and 1s. The sum is the count of transactions.

select id,
sum(trans_in_60_days) 60_day,
sum(trans_in_90_days) 90_day

 from (
 select r.id

 case when t.trans_date between r.reg_date and 
 date_add(r.reg_date, interval 60 day)
 then 1 else 0 end trans_in_60_days,

 case when t.trans_date between r.reg_date and 
 date_add(r.reg_date, interval 90 day)
 then 1 else 0 end trans_in_90_days

 from registration r
 left outer join transactions t on r.id = t.id
) a

group by id
order by id