query for contacts with board forum access
[civicrm-scripts.git] / board-forum-contacts.sql
CommitLineData
523c32dc
AE
1
2-- SPDX-FileCopyrightText: 2023 Andrew Engelbrecht
3--
4-- SPDX-License-Identifier: GPL-3.0-or-later
5
6select c.id from civicrm_contact c
7where c.is_deleted = 0
8and c.id not in (
9 select contact_id from civicrm_group_contact
10 where id = 1978 and status = 'Added' -- adhoc exclusion group
11) and (
12 c.id in (
13 select contact_id from civicrm_group_contact
14 where id = 1977 and status = 'Added' -- adhoc inclusion group
15 ) or (
16 c.id in (
17 select contact_id from civicrm_membership
18 where status_id in (1, 2, 3) -- is a member: new, current or grace
19 ) and (
20 c.id in (
21 select contact_id from civicrm_membership
894bf2b7 22 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
523c32dc
AE
23 ) or c.id in (
24 select contact_id from civicrm_contribution
25 where contribution_status_id = 1 and receive_date >= '2018-01-19' and receive_date <= '2022-10-19'
26 group by contact_id
13223cc2 27 having sum(total_amount) >= '120.00' -- donated $120 or more during time period
523c32dc
AE
28 )
29 )
30 )
6b97c191 31) order by id asc
16b5030d 32into outfile '/var/lib/mysql-files/board-forum-contacts4.csv' fields terminated by ','
6b97c191 33;
523c32dc 34