Test data in _Sent data view table - A log of sent emails are saved in this table
+-------+------------------+------------------+------------------------------------+
| JobID | SubscriberID | SubscriberKey | EventDate |
+-------+------------------+------------------+------------------------------------+
| 12301 | emai1@gmail.com | emai1@gmail.com | Monday, March 01, 2021 9:45 AM |
| 12302 | email2@gmail.com | email2@gmail.com | Monday, March 01, 2021 9:50 AM |
| 12303 | email3@gmail.com | email3@gmail.com | Tuesday, March 02, 2021 10:45 AM |
| 12304 | email4@gmail.com | email4@gmail.com | Wednesday, March 03, 2021 11:45 AM |
| 12305 | emai1@gmail.com | emai1@gmail.com | Thursday, March 04, 2021 1:10 AM |
| 12306 | email3@gmail.com | email3@gmail.com | Friday, March 05, 2021 3:20 AM |
+-------+------------------+------------------+------------------------------------+
Test data in _Jobt data view table - A log of sent email job is saved in this table (one batch of send is associated with one job i.e., if 10,000 emails were sent in one batch then 10,000 rows will have same jobID)
+-------+--------------+------------------------------------+-------------+------------------+
| JobID | EmailName | CreatedDate | Category | SuppressTracking |
+-------+--------------+------------------------------------+-------------+------------------+
| 12301 | Email Name 1 | Monday, March 01, 2021 9:45 AM | my tracking | FALSE |
| 12302 | Email Name 2 | Monday, March 01, 2021 9:50 AM | my tracking | FALSE |
| 12303 | Email Name 3 | Tuesday, March 02, 2021 10:45 AM | my tracking | FALSE |
| 12304 | Email Name 4 | Wednesday, March 03, 2021 11:45 AM | my tracking | FALSE |
| 12305 | Email Name 5 | Thursday, March 04, 2021 1:10 AM | my tracking | FALSE |
| 12306 | Email Name 6 | Friday, March 05, 2021 3:20 AM | my tracking | FALSE |
| 12307 | Email Name 7 | Saturday, March 06, 2021 1:10 AM | my tracking | FALSE |
| 12308 | Email Name 8 | Sunday, March 07, 2021 2:30 PM | my tracking | FALSE |
| 12309 | Email Name 9 | Monday, March 08, 2021 1:15 AM | my tracking | FALSE |
+-------+--------------+------------------------------------+-------------+------------------+
I have created a query to get count of subscribers who received emails in a specific time frame
SELECT j.JobID AS Job_ID, j.EmailName AS Email_Name, count(DISTINCT s.SubscriberID) as Sub_Count
FROM _Sent s WITH (NOLOCK)
INNER JOIN _Job j WITH (NOLOCK) on j.JobID = s.JobID
where
j.SuppressTracking = 'False' AND j.category = 'my tracking' AND cast(j.CreatedDate As Date) >= cast('2021-03-01' as Date)
AND cast(j.CreatedDate As Date) <= cast('2021-03-31' as Date)
GROUP BY j.JobID
But what do i need to do in the query if i am am looking for:
1) subscribers who received more than 1 emails within the time frame?
Desired output:
+------------------+-------------------------------------+
| SubscriberKey | EmailName_Count_received_by_contact |
+------------------+-------------------------------------+
| emai1@gmail.com | 2 |
| email3@gmail.com | 2 |
| email5@gmail.com | 3 |
+------------------+-------------------------------------+
2) distinct email names for the subscribers who received multiple emails
Desired output:
+--------------+
| EmailName |
+--------------+
| Email Name 1 |
| Email Name 3 |
| Email Name 7 |
| Email Name 8 |
| Email Name 9 |
+--------------+