From cf5df3e47636b40e7c78c17d3a7f157608c73d89 Mon Sep 17 00:00:00 2001 From: Kailash Nadh Date: Mon, 26 Nov 2018 19:06:11 +0530 Subject: [PATCH] Fix counting unsubbed users in campaign stats counts --- queries.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/queries.sql b/queries.sql index 7396fd8..36229c9 100644 --- a/queries.sql +++ b/queries.sql @@ -243,7 +243,7 @@ counts AS ( SELECT id AS campaign_id, COUNT(subscriber_lists.subscriber_id) AS to_send, COALESCE(MAX(subscriber_lists.subscriber_id), 0) AS max_subscriber_id FROM camps LEFT JOIN campaign_lists ON (campaign_lists.campaign_id = camps.id) - LEFT JOIN subscriber_lists ON (subscriber_lists.list_id = campaign_lists.list_id) + LEFT JOIN subscriber_lists ON (subscriber_lists.list_id = campaign_lists.list_id AND subscriber_lists.status != 'unsubscribed') WHERE campaign_lists.campaign_id = ANY(SELECT id FROM camps) GROUP BY camps.id ),