Re: Counting unique rows as an aggregate.

From: Lennin Caro <lennin(dot)caro(at)yahoo(dot)com>
To: pgsql-general(at)postgresql(dot)org, r_musta <zepolen(at)gmail(dot)com>
Subject: Re: Counting unique rows as an aggregate.
Date: 2008-10-01 02:52:41
Message-ID: 567872.86986.qm@web59516.mail.ac4.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

--- On Tue, 9/30/08, r_musta <zepolen(at)gmail(dot)com> wrote:

> From: r_musta <zepolen(at)gmail(dot)com>
> Subject: Re: [GENERAL] Counting unique rows as an aggregate.
> To: pgsql-general(at)postgresql(dot)org
> Date: Tuesday, September 30, 2008, 6:55 AM
> On Sep 30, 2:36 am, t(dot)(dot)(dot)(at)sss(dot)pgh(dot)pa(dot)us (Tom Lane) wrote:
> > > SELECT count_unique(make), count_unique(color)
> from table WHERE >criteria<;
> >
> > I must be missing something, because I don't see
> why you couldn't do
> > SELECT count(distinct make), count(distinct color)
> from table WHERE >criteria<;
>
> I didn't explain well, I want the count of each
> distinct value in a
> column, eg, if the color column has 50 rows,
> 20x'red', 10x'green',
> 20x'blue' - it will give me those results.
>
> SELECT count(distinct color) would return 3 - which is the
> count of
> distinct values, which is not what I want.
>

SELECT count(color),color from table group by color

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Craig Ringer 2008-10-01 03:56:57 Re: Standalone Windows Installation
Previous Message Scott Marlowe 2008-10-01 02:29:20 Re: Running 2 versions of postgres on the same server at the same time ???