Skip to content
Advertisement

SQL query to consider exactly last 3 email send count and then return the respective click count

I have a table – ‘clicks_plus_noClicks_raw’ like below

If customer has not clicked on any of the last 3 emails we sent(exact 3), I want to add the result to final table with count as 0.

a@gmail.com & b@gmail.com should be skipped because we dint send them 3 emails yet.The final results should be only for ones we sent 3 emails.

I have this query, but the query counts even last 1 send, which is not what I want.

Advertisement

Answer

You need a HAVING clause in your query to check for the number of emails and a WHERE clause to return only the last 3 emails:

See the demo.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement