Skip to content

Instantly share code, notes, and snippets.

@trullock
Created November 7, 2012 09:39
Show Gist options
  • Save trullock/4030415 to your computer and use it in GitHub Desktop.
Save trullock/4030415 to your computer and use it in GitHub Desktop.
set transaction isolation level read uncommitted
select
c.[Id],
c.[Name],
c.[SentOn],
count(distinct s.Id) as sent,
sum(case when s.[Bounced] = 1 then 1 else 0 end) as bounced,
sum(case when s.[Complained] = 1 then 1 else 0 end) as complained,
sum(case when s.[Opened] = 1 then 1 else 0 end) as opened,
count(ec.[Id]) as clicks
from [EmailCampaign] c
left join [Email_Sent] s on c.Id = s.CampaignId
left join [Email_Clicked] ec on ec.[EmailId] = s.[Id]
group by
c.[Id],
c.[Name],
c.[SentOn]
order by
[SentOn] desc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment