My prior comment simply answers your question. You likely can rewrite your query so that a separate grouping layer is not needed (or rather the group by would exist in the main query and you minimize the case/sub-select column queries and use aggregates and case instead).
David J. -- View this message in context: http://postgresql.1045698.n5.nabble.com/pivot-query-with-count-tp5752072p5752078.html Sent from the PostgreSQL - sql mailing list archive at Nabble.com. -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql