Paste this into a new question or an answer at dba.stackexchange.com:
<!-- --> > CREATE TABLE classroom_observations (id SERIAL, created_at TIMESTAMPTZ); > CREATE TABLE training_modules (id SERIAL, created_at TIMESTAMPTZ); > CREATE TABLE teachers_workshops (id SERIAL, created_at TIMESTAMPTZ); > > INSERT INTO classroom_observations VALUES > (1, '2019-04-20 10:36:06+02') > ,(2, '2019-05-22 15:22:33+02') > ,(3, '2019-05-23 15:22:33+02') > ,(4, '2019-05-24 15:22:33+02'); > INSERT INTO training_modules VALUES > (1, '2019-03-20 10:36:06+02') > ,(2, '2019-04-22 15:22:33+02') > ,(3, '2019-04-23 15:22:33+02') > ,(4, '2019-05-24 15:22:33+02'); > INSERT INTO teachers_workshops VALUES > (1, '2019-03-20 10:36:06+02'); > > <pre> > ✓ > > ✓ > > ✓ > 4 rows affected > 4 rows affected > 1 rows affected > </pre> <!-- --> > SELECT to_char(mon, 'YYYY-MM') AS month > , COALESCE(co.ct, 0) AS co_count > , COALESCE(tm.ct, 0) AS tm_count > , COALESCE(tw.ct, 0) AS tw_count > FROM ( > SELECT date_trunc('month', created_at) AS mon, count(*) AS ct > FROM classroom_observations > GROUP BY mon > ) co > FULL JOIN ( > SELECT date_trunc('month', created_at) AS mon, count(*) AS ct > FROM training_modules > GROUP BY mon > ) tm USING (mon) > FULL JOIN ( > SELECT date_trunc('month', created_at) AS mon, count(*) AS ct > FROM teachers_workshops > GROUP BY mon > ) tw USING (mon) > ORDER BY mon; > > <pre> > month | co_count | tm_count | tw_count > :------ | -------: | -------: | -------: > 2019-03 | 0 | 1 | 1 > 2019-04 | 1 | 2 | 0 > 2019-05 | 3 | 1 | 0 > </pre> *db<>fiddle [here](https://dbfiddle.uk/?rdbms=postgres_11&fiddle=68e84cd308fa84639f074be32484e913)*
back to fiddle