forked from knadh/listmonk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stats.sql
25 lines (25 loc) · 840 Bytes
/
stats.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
-- WITH l AS (
-- SELECT type, COUNT(id) AS count FROM lists GROUP BY type
-- ),
-- subs AS (
-- SELECT status, COUNT(id) AS count FROM subscribers GROUP by status
-- ),
-- subscrips AS (
-- SELECT status, COUNT(subscriber_id) AS count FROM subscriber_lists GROUP by status
-- ),
-- orphans AS (
-- SELECT COUNT(id) AS count FROM subscribers LEFT JOIN subscriber_lists ON (subscribers.id = subscriber_lists.subscriber_id)
-- WHERE subscriber_lists.subscriber_id IS NULL
-- ),
-- camps AS (
-- SELECT status, COUNT(id) AS count FROM campaigns GROUP by status
-- )
-- SELECT t3.*, t5.* FROM l t1
-- LEFT JOIN LATERAL (
-- SELECT JSON_AGG(t2.*) AS lists
-- FROM (SELECT * FROM l) t2
-- ) t3 ON TRUE
-- LEFT JOIN LATERAL (
-- SELECT JSON_AGG(t4.*) AS subs
-- FROM (SELECT * FROM subs) t4
-- ) t5 ON TRUE;