Received: from localhost (maia-5.hub.org [200.46.204.182]) by postgresql.org (Postfix) with ESMTP id 439B29FBB9E for ; Mon, 14 May 2007 19:55:57 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.182]) (amavisd-maia, port 10024) with ESMTP id 96918-03 for ; Mon, 14 May 2007 19:55:49 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) by postgresql.org (Postfix) with ESMTP id C40389FB985 for ; Mon, 14 May 2007 19:55:53 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.3 Received: from outM.internet-mail-service.net (outM.internet-mail-service.net [216.240.47.236]) by svr4.postgresql.org (Postfix) with ESMTP id F2E595AF027 for ; Mon, 14 May 2007 22:55:52 +0000 (GMT) Received: from mx0.idiom.com (HELO idiom.com) (216.240.32.160) by out.internet-mail-service.net (qpsmtpd/0.32) with ESMTP; Mon, 14 May 2007 15:55:45 -0700 Received: from [192.168.1.109] (adsl-71-135-160-185.dsl.pltn13.pacbell.net [71.135.160.185]) by idiom.com (Postfix) with ESMTP id 7C7C5125A28 for ; Mon, 14 May 2007 15:55:45 -0700 (PDT) Message-ID: <4648E8F1.4020609@obviously.com> Date: Mon, 14 May 2007 15:55:45 -0700 From: Bryce Nesbitt User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.2) Gecko/20061107 SUSE/1.1.1-0.1 SeaMonkey/1.1.1 MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: Doing a conditional aggregate (e.g. count(*) if x=y) in postgres? Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200705/111 X-Sequence-Number: 28391 All; Is there a way to get a conditional aggregate? I have this two column view: SELECT count(*) AS count, xx_plan.plan_name FROM xx_membership JOIN xx_account USING (account_id) JOIN xx_plan USING (plan_id) WHERE xx_membership.status = 10 GROUP BY xx_plan.plan_name; And would like to add additional columns (not rows) breaking out "status=20" and "status=30" totals. Is this possible without a stored procedure?