Skip to content

Instantly share code, notes, and snippets.

@caioagiani
Created July 11, 2024 16:24
Show Gist options
  • Save caioagiani/33a5221d02d70bd458fc5c65bae3990e to your computer and use it in GitHub Desktop.
Save caioagiani/33a5221d02d70bd458fc5c65bae3990e to your computer and use it in GitHub Desktop.
SELECT
j.JobID,
j.EmailName,
j.DeliveredTime AS SendTime,
o.EventDate AS EventTime,
s.EmailAddress,
s.SubscriberKey,
'Opened' AS EventType
FROM [_Job] j
INNER JOIN [_Open] o ON j.JobID = o.JobID
INNER JOIN [_Subscribers] s ON o.SubscriberID = s.SubscriberID
WHERE o.IsUnique = 1
AND o.EventDate > DATEADD(day, -90, GETDATE())
UNION ALL
SELECT
j.JobID,
j.EmailName,
j.DeliveredTime AS SendTime,
c.EventDate AS EventTime,
s.EmailAddress,
s.SubscriberKey,
'Clicked' AS EventType
FROM [_Job] j
INNER JOIN [_Click] c ON j.JobID = c.JobID
INNER JOIN [_Subscribers] s ON c.SubscriberID = s.SubscriberID
WHERE c.IsUnique = 1
AND c.EventDate > DATEADD(day, -90, GETDATE())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment