I have a table that holds all the emails sent for email campaigns:
ID | campaign_id | date_sent | date_delivered | email | status
Status
holds delivery information, DELIVERED
or UNDELIVERED
. I want to find all email addresses that their status is UNDELIVERED
for the last five campaigns.
For example, [email protected]
used to be ok and received all campaigns, but now the email address does not exist and the last 5 campaigns status is UNDELIVERED
.
So far I am doing:
SELECT *, count(id) as occ FROM message_details WHERE status='FAILED' GROUP BY email
But this is showing the total of undelivered for every address and not the last 5.