Count of records in a row

From: Robert James <srobertjames(at)gmail(dot)com>
To: Postgres General <pgsql-general(at)postgresql(dot)org>
Subject: Count of records in a row
Date: 2013-10-22 00:38:52
Message-ID: CAGYyBghMhBve35jmjv1X7Ga+g-Ry7hDr+C3h8uid3CqOSFR04w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I have a table of event_id, event_time. Many times, several events
happen in a row. I'd like a query which replaces all of those events
with a single record, showing the count.

Eg: Take A,A,A,B,C,A,D,A,A,D,D,B,C,C and return: A,3; B,1; C,1; A,1;
D,1; A,2; D,2; B,1; C,2

How can I do that?

Responses

Browse pgsql-general by date

  From Date Subject
Next Message David Johnston 2013-10-22 00:54:14 Re: Count of records in a row
Previous Message David Johnston 2013-10-21 23:52:46 Re: Bug? Function with side effects not evaluated in CTE