Skip site navigation (1) Skip section navigation (2)

Re: Counting unique rows as an aggregate.

From: r_musta <zepolen(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Counting unique rows as an aggregate.
Date: 2008-09-30 06:55:46
Message-ID: 5d397b73-372d-4bb1-9318-09211f30cc46@m73g2000hsh.googlegroups.com (view raw or flat)
Thread:
Lists: pgsql-general
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.

In response to

Responses

pgsql-general by date

Next:From: r_mustaDate: 2008-09-30 06:59:50
Subject: Re: Counting unique rows as an aggregate.
Previous:From: A. KretschmerDate: 2008-09-30 06:52:38
Subject: Re: dbsamples from pgfoundry

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group