Skip to content

Instantly share code, notes, and snippets.

@jthandy
Created April 14, 2016 13:05
Show Gist options
  • Save jthandy/e56a048d89e21140612e5ccdd01ed4ae to your computer and use it in GitHub Desktop.
Save jthandy/e56a048d89e21140612e5ccdd01ed4ae to your computer and use it in GitHub Desktop.
with events as (
select
campaign_id, email_id, sent_date,
decode(hard_bounced_date, null, 0, 1) as hard_bounced,
decode(first_opened_date, null, 0, 1) as opened,
decode(first_clicked_date, null, 0, 1) as clicked,
decode(unsubscribed_date, null, 0, 1) as unsubscribed
from {{env.schema}}.mailchimp_email_summary
)
select
date_trunc('month', sent_date) as month,
count(*) as sends,
sum(opened) as opens,
sum(clicked) as clicks,
avg(opened::float) as open_rate,
avg(clicked::float) as click_rate
from events
group by month
order by month
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment