another script for civi contacts (board forum)
authorAndrew Engelbrecht <andrew@fsf.org>
Mon, 17 Jul 2023 19:40:27 +0000 (15:40 -0400)
committerAndrew Engelbrecht <andrew@fsf.org>
Mon, 17 Jul 2023 19:40:27 +0000 (15:40 -0400)
board-forum-contacts-on-join.sql [new file with mode: 0644]

diff --git a/board-forum-contacts-on-join.sql b/board-forum-contacts-on-join.sql
new file mode 100644 (file)
index 0000000..c71dc2f
--- /dev/null
@@ -0,0 +1,29 @@
+
+-- SPDX-FileCopyrightText: 2023 Andrew Engelbrecht
+--
+-- SPDX-License-Identifier: GPL-3.0-or-later
+
+select c.id from civicrm_contact c
+where c.is_deleted = 0
+and c.id not in (
+    select contact_id from civicrm_group_contact
+    where id = 1978 and status = 'Added' -- adhoc exclusion group
+) and (
+    c.id not in (
+        select contact_id from civicrm_membership
+        where status_id in (1, 2, 3) -- is a member: new, current or grace
+    ) and (
+        c.id in (
+            select contact_id from civicrm_membership
+            where status_id in (1, 2, 3, 4) and end_date >= '2018-01-19' and join_date <= '2022-10-19' -- was a member during time period
+        ) or c.id in (
+            select contact_id from civicrm_contribution
+            where contribution_status_id = 1 and receive_date >= '2018-01-19' and receive_date <= '2022-10-19'
+            group by contact_id
+            having sum(total_amount) >= '120.00' -- donated $120 or more during time period
+        )
+    )
+) order by id asc
+into outfile '/var/lib/mysql-files/board-forum-contacts-on-join2.csv' fields terminated by ','
+;
+