Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UQr9V-0001wd-31 for pgsql-sql@arkaria.postgresql.org; Sat, 13 Apr 2013 03:29:21 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1UQr9U-0005z1-Jy for pgsql-sql@arkaria.postgresql.org; Sat, 13 Apr 2013 03:29:20 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UQr9U-0005yw-1j for pgsql-sql@postgresql.org; Sat, 13 Apr 2013 03:29:20 +0000 Received: from sam.nabble.com ([216.139.236.26]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UQr9Q-0007cH-Rl for pgsql-sql@postgresql.org; Sat, 13 Apr 2013 03:29:19 +0000 Received: from [192.168.236.26] (helo=sam.nabble.com) by sam.nabble.com with esmtp (Exim 4.72) (envelope-from ) id 1UQr9P-0005Or-TD for pgsql-sql@postgresql.org; Fri, 12 Apr 2013 20:29:15 -0700 Date: Fri, 12 Apr 2013 20:29:15 -0700 (PDT) From: David Johnston To: pgsql-sql@postgresql.org Message-ID: <1365823755894-5752078.post@n5.nabble.com> In-Reply-To: <1365823565069-5752077.post@n5.nabble.com> References: <1365823565069-5752077.post@n5.nabble.com> Subject: Re: pivot query with count MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: 1.8 (+) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-sql Precedence: bulk Sender: pgsql-sql-owner@postgresql.org 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