Unanswered: SQL count distinct returning 1's for multiple rows of same ID
I have a marketing table with a customer ID, email date, and a close date (when the sale is closed). I have a filter that basically says the closed date must occur within 30 days of the email date. The problem is that in certain cases where the close date occurs within 30 days of the email_date, I am double counting. I want the count to only show a 1 for the most recent email date, and never to double count.
Sample query to give you an idea:
,count(distinct case when closed_date - email-date <= interval '30 days' then customer_id else null end)
Output Example Showing the double counting Problem:
Customer ID Email Date Count(distinct) Closed_Date