X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 83857567D3 for ; Thu, 17 Mar 2005 20:18:57 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 58821-04 for ; Thu, 17 Mar 2005 20:18:56 +0000 (GMT) Received: from mta08-winn.mailhost.ntl.com (smtpout16.mailhost.ntl.com [212.250.162.16]) by svr1.postgresql.org (Postfix) with ESMTP id 9194C56745 for ; Thu, 17 Mar 2005 20:18:54 +0000 (GMT) Received: from aamta05-winn.mailhost.ntl.com ([212.250.162.8]) by mta08-winn.mailhost.ntl.com with ESMTP id <20050317201855.FQWR928.mta08-winn.mailhost.ntl.com@aamta05-winn.mailhost.ntl.com> for ; Thu, 17 Mar 2005 20:18:55 +0000 Received: from [192.168.0.103] (really [213.105.102.236]) by aamta05-winn.mailhost.ntl.com with ESMTP id <20050317201854.MHYG1280.aamta05-winn.mailhost.ntl.com@[192.168.0.103]> for ; Thu, 17 Mar 2005 20:18:54 +0000 Subject: Consecutive row count query From: Leon Stringer To: pgsql-sql@postgresql.org Content-Type: text/plain Date: Thu, 17 Mar 2005 20:21:24 +0000 Message-Id: <1111090884.22783.5.camel@localhost.localdomain> Mime-Version: 1.0 X-Mailer: Evolution 2.0.2 (2.0.2-3) Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.78 tagged_above=0 required=5 tests=AWL, DNS_FROM_RFC_POST X-Spam-Level: X-Archive-Number: 200503/247 X-Sequence-Number: 20726 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. Obviously I could store the table as: col1 col_order col_count -------------------------- Apple 1 2 Orange 2 1 Banana 3 1 Apple 4 1 But since (in my intended table) most rows will have col_count = 1, this seems like unnecessary normalization (and semantically "wrong"). Thanks in advance for any help, Leon Stringer