Re: Counting Distinct Records

From: Thomas F(dot)O'Connell <tfo(at)sitening(dot)com>
To: Stephan Szabo <sszabo(at)megazone(dot)bigpanda(dot)com>
Cc: PgSQL - SQL <pgsql-sql(at)postgresql(dot)org>
Subject: Re: Counting Distinct Records
Date: 2004-11-17 19:27:17
Message-ID: B16EB296-38CE-11D9-95C2-000D93AE0944@sitening.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

The specific problem I'm trying to solve involves a user table with
some history.

Something like this:

create table user_history (
user_id int
event_time_stamp timestamp
);

I'd like to be able to count the distinct user_ids in this table, even
if it were joined to other tables.

-tfo

--
Thomas F. O'Connell
Co-Founder, Information Architect
Sitening, LLC
http://www.sitening.com/
110 30th Avenue North, Suite 6
Nashville, TN 37203-6320
615-260-0005

On Nov 17, 2004, at 8:52 AM, Stephan Szabo wrote:

> On Tue, 16 Nov 2004, Thomas F.O'Connell wrote:
>
>> Hmm. I was more interested in using COUNT( * ) than DISTINCT *.
>>
>> I want a count of all rows, but I want to be able to specify which
>> columns are distinct.
>
> I'm now a bit confused about exactly what you're looking for in the
> end.
> Can you give a short example?
>
>> That's definitely an interesting approach, but testing doesn't show it
>> to be appreciably faster.
>>
>> If I do a DISTINCT *, postgres will attempt to guarantee that there
>> are
>> no duplicate values across all columns rather than a subset of
>> columns?
>> Is that right?
>
> It guarantees one output row for each distinct set of column values
> across
> all columns.

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Harry Smith 2004-11-18 03:01:46 Usenet Discussion Proposal
Previous Message Richard Huxton 2004-11-17 15:24:23 Re: session_id