From: Bruno Wolff III <bruno@wolff.to>
To: Leon Stringer <leon.stringer@ntlworld.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: Consecutive row count query
Date: Thu, 17 Mar 2005 15:15:59 -0600
Message-ID: <20050317211559.GB2074@wolff.to> (raw)
In-Reply-To: <1111090884.22783.5.camel@localhost.localdomain>
References: <1111090884.22783.5.camel@localhost.localdomain>
On Thu, Mar 17, 2005 at 20:21:24 +0000,
Leon Stringer <leon.stringer@ntlworld.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.
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: bruno@wolff.to, leon.stringer@ntlworld.com
Subject: Re: Consecutive row count query
In-Reply-To: <20050317211559.GB2074@wolff.to>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox