Re: multiple count functions in a select statement

From: Mike Rylander <miker(at)purplefrog(dot)com>
To: Jeannie Stevenson <webteam(at)wes-state(dot)com>
Cc: postgresql <pgsql-general(at)postgresql(dot)org>
Subject: Re: multiple count functions in a select statement
Date: 2004-06-01 11:36:44
Message-ID: 200406010736.44946.miker@purplefrog.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Monday 31 May 2004 04:32 pm, Oliver Elphick wrote:
> On Thu, 2004-05-27 at 17:38, Jeannie Stevenson wrote:
> ...
>
> > In MSSQL I would use
> >
> > select
> > count_1=(select count(ad_code) AS "CP" from leads where ad_code =
> > '555'),
> > count_2=(select count(ad_code) AS HED" from leads where ad_code =
> > '222'),
> > etc
>
> SELECT
> (select count(ad_code) AS "CP"
> from leads where ad_code = '555') AS count_1,
> (select count(ad_code) AS HED"
> from leads where ad_code = '222') AS count_2,
> ...etc...

Or, if you want a count of every ad_code:

SELECT ad_code, COUNT(ad_code) FROM leads GROUP BY ad_code;

-miker

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Levan, Jerry 2004-06-01 12:40:19 Running Totals and other stuff....
Previous Message Richard Huxton 2004-06-01 11:24:26 Re: Separating application from data