1

Having trouble getting the SQL right for this. I'm looking to get a total count of emails a specific subscriber received in the last 30 days. But it keeps failing. I'd also like to be able to query what those emails were during that same timeframe.

SELECT s.SubscriberKey COUNT (SubscriberKey) AS SENT_COUNT FROM _Sent
WHERE JobID IN (SELECT JobID FROM _Job WHERE SubscriberKey = 'XXX')
and EventDate between '2022-07-18' and '2022-08-18'
1
  • 1
    What do you mean by "keeps failing"? Commented Aug 12, 2022 at 18:37

1 Answer 1

2
SELECT s.SubscriberKey, COUNT (s.SubscriberKey) AS SENT_COUNT 
    FROM _Sent s
    inner join _Job j on j.jobid = s.jobid
WHERE SubscriberKey = 'XXX'
  and s.EventDate > getdate()-30
group by s.SubscriberKey

Is this what you want?

2
  • Yes, thank you!
    – ld123
    Commented Aug 12, 2022 at 20:51
  • Props for this sargable criteria! The getDate() returns a timestamp, so it'd be better to make sure you get the whole day of events with and s.EventDate > convert(date, getDate()-30). Commented Aug 12, 2022 at 21:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .