Skip to content

Instantly share code, notes, and snippets.

@gshutler
Forked from trullock/gist:4030415
Created November 7, 2012 09:54
Show Gist options
  • Save gshutler/4030506 to your computer and use it in GitHub Desktop.
Save gshutler/4030506 to your computer and use it in GitHub Desktop.
set transaction isolation level read uncommitted
select
c.[Id],
c.[Name],
c.[SentOn],
count(s.Id) as sent,
sum(s.[Bounced]) as bounced,
sum(s.[Complained]) as complained,
sum(s.[Opened]) as opened,
(select count(1) from [Email_Sent] s on c.Id = s.CampaignId inner join [Email_Clicked] ec on ec.[EmailId] = s.[Id]) as clicks
from [EmailCampaign] c
left join [Email_Sent] s on c.Id = s.CampaignId
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