I am using Postgres 9.4 and I have a query that looks like the following:
SELECT attendees.event_id, attendees.user_id, users.tags
FROM users, attendees
WHERE 'crystal:promo' = ANY(users.tags)
AND users.id = attendees.user_id
AND attendees.status = 'paid'
GROUP BY attendees.event_id, attendees.user_id, users.tags
ORDER BY attendees.event_id desc;
Result:
event_id | user_id | tags
----------+---------+------
1 | 2 | ...
1 | 4 | ...
1 | 7 | ...
I'd like to add a summary column for each row that is the total number of people per event independent of user tags such that the result would be something like:
select count(*) from attendees where status='paid' group by event_id
and joined with the above results (assuming 11 paid):
event_id | user_id | tags | total_event_paid
----------+---------+------+------------------
1 | 2 | ... | 11
1 | 4 | ... | 11
1 | 7 | ... | 11