Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UQr6U-0001kU-4e for pgsql-sql@arkaria.postgresql.org; Sat, 13 Apr 2013 03:26:14 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1UQr6T-00054J-G0 for pgsql-sql@arkaria.postgresql.org; Sat, 13 Apr 2013 03:26:13 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UQr6R-00054B-Kj for pgsql-sql@postgresql.org; Sat, 13 Apr 2013 03:26:11 +0000 Received: from sam.nabble.com ([216.139.236.26]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UQr6N-0007bq-N3 for pgsql-sql@postgresql.org; Sat, 13 Apr 2013 03:26:10 +0000 Received: from [192.168.236.26] (helo=sam.nabble.com) by sam.nabble.com with esmtp (Exim 4.72) (envelope-from ) id 1UQr6L-0005Fk-2P for pgsql-sql@postgresql.org; Fri, 12 Apr 2013 20:26:05 -0700 Date: Fri, 12 Apr 2013 20:26:05 -0700 (PDT) From: David Johnston To: pgsql-sql@postgresql.org Message-ID: <1365823565069-5752077.post@n5.nabble.com> In-Reply-To: References: 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 SELECT num_ads, sum(...), sum(...), .... FROM ( your query here ) GROUP BY num_ads; BTW, While "SELECT '1' "num_ads" is valid syntax I recommend you use the "AS" keyword. '1' AS "num_ads" David J. -- View this message in context: http://postgresql.1045698.n5.nabble.com/pivot-query-with-count-tp5752072p5752077.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