Re: [GENERAL] Any ideas why this doesn't work or how to rewrite it? - Mailing list pgsql-general

From Brett W. McCoy
Subject Re: [GENERAL] Any ideas why this doesn't work or how to rewrite it?
Date
Msg-id Pine.BSI.3.91.990429140136.6326F-100000@access1.lan2wan.com
Whole thread Raw
In response to Re: [GENERAL] Any ideas why this doesn't work or how to rewrite it?  (Herouth Maoz <herouth@oumail.openu.ac.il>)
Responses Re: [GENERAL] Any ideas why this doesn't work or how to rewrite it?  (Herouth Maoz <herouth@oumail.openu.ac.il>)
List pgsql-general
On Thu, 29 Apr 1999, Herouth Maoz wrote:

> At 18:50 +0300 on 28/04/1999, Aaron Holtz wrote:
>
>
> > db=> select count(distinct customer_username) from customerdata;
> > ERROR:  parser: parse error at or near "distinct"
> >
> > How do you get a count of distinct data output via postgres?  I can always
> > just count the number of tuples returned but this seemed to be a valid
> > query.
>
> Valid it is, but not yet supported in PostgreSQL.
>
> An (ugly) workaround would be something along the lines of:
>
> SELECT count(customer_username)
> FROM customerdata c1
> WHERE int( oid ) = (
>   SELECT min( int( c2.oid ) )
>   FROM customerdata c2
>   WHERE c1.customer_username = c2.customer_username
> );

I think, Aaron, you could get a count of distinct customer names like this:

SELECT DISTINCT customer_username, COUNT(*) FROM customerdata
GROUP BY customer_username;

This will give you 2 columns, one with the distinct customer_usernames
and the second with the count of each.  The GROUP BY caluse is important
here.  This looks like what you wanted in your original query.

Brett W. McCoy
                                         http://www.lan2wan.com/~bmccoy
-----------------------------------------------------------------------
Schapiro's Explanation:
    The grass is always greener on the other side -- but that's
because they use more manure.


pgsql-general by date:

Previous
From: jim@reptiles.org (Jim Mercer)
Date:
Subject: serious bug in "alter table tbname rename to newname"
Next
From: Herouth Maoz
Date:
Subject: Re: [GENERAL] Any ideas why this doesn't work or how to rewrite it?