Re: multiple count functions in a select statement - Mailing list pgsql-general

From Mike Rylander
Subject Re: multiple count functions in a select statement
Date
Msg-id 200406010736.44946.miker@purplefrog.com
Whole thread Raw
In response to Re: multiple count functions in a select statement  (Oliver Elphick <olly@lfix.co.uk>)
List 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

pgsql-general by date:

Previous
From: Richard Huxton
Date:
Subject: Re: Separating application from data
Next
From: "Levan, Jerry"
Date:
Subject: Running Totals and other stuff....