1 CREATE OR REPLACE VIEW extend_reporter.full_circ_count AS
2 SELECT cp.id, COALESCE(c.circ_count, 0::bigint) + COALESCE(count(DISTINCT circ.id), 0::bigint) + COALESCE(count(DISTINCT acirc.id), 0::bigint) AS circ_count
4 LEFT JOIN extend_reporter.legacy_circ_count c USING (id)
5 LEFT JOIN "action".circulation circ ON circ.target_copy = cp.id
6 LEFT JOIN "action".aged_circulation acirc ON acirc.target_copy = cp.id
7 GROUP BY cp.id, c.circ_count;