Re: Consecutive row count query

From: Bruno Wolff III <bruno(at)wolff(dot)to>
To: Leon Stringer <leon(dot)stringer(at)ntlworld(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Consecutive row count query
Date: 2005-03-17 21:15:59
Message-ID: 20050317211559.GB2074@wolff.to
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Thu, Mar 17, 2005 at 20:21:24 +0000,
Leon Stringer <leon(dot)stringer(at)ntlworld(dot)com> wrote:
> Hi,
>
> I wondered if anyone could answer the following question:
>
> If I have a table such as the one below:
>
> col1 col_order
> -----------
> Apple 1
> Apple 2
> Orange 3
> Banana 4
> Apple 5
>
> Is there a way I can get the following results:
>
> Apple 2
> Orange 1
> Banana 1
> Apple 1
>
> i.e. Each row is printed ordered by col_order but consecutive
> appearances of the same col1 result in only a single line in the result
> with the number of consecutive appearances.

Which col_order value do you expect to use in ordering?

You can probably join a grouped version of the table to get the counts
with a distinct on version of the table to do what you want.

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Jaime Casanova 2005-03-17 21:32:31 Re: Consecutive row count query
Previous Message Leon Stringer 2005-03-17 20:21:24 Consecutive row count query