Doing a conditional aggregate (e.g. count(*) if x=y) in postgres?

From: Bryce Nesbitt <bryce1(at)obviously(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: Doing a conditional aggregate (e.g. count(*) if x=y) in postgres?
Date: 2007-05-14 22:55:45
Message-ID: 4648E8F1.4020609@obviously.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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?

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Paul Lambert 2007-05-14 22:56:19 Re: pg_dump?
Previous Message Richard Dunne 2007-05-14 22:48:17 pg_dump?