Skip site navigation (1) Skip section navigation (2)

Re: querying the value of the previous row

From: John R Pierce <pierce(at)hogranch(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: querying the value of the previous row
Date: 2010-03-12 06:14:37
Message-ID: 4B99DBCD.9020707@hogranch.com (view raw or flat)
Thread:
Lists: pgsql-general
Chris Velevitch wrote:
> I'm to write a query like:-
>
> select
>      case when column_name1 <> value_of_previous(column_name1)
>           then column_name1 end as column
>     ,column_name2
> from table
> ordered by column_name1, column_name2
>
> in order to get:-
>
> column        | column_name2
> --------------+--------------
> value_1_c1    |   value_1_c2
>               |   value_2_c2
>               |   value_3_c2
> value_2_c1    |   value_4_c2
>               |   value_5_c2
>               |   value_6_c2
> value_3_c1    |   value_7_c2
>               |   value_8_c2
>               |   value_9_c2
>
> How do I do this? (I'm using pg 7.4)

what does 'previous' mean here?   thats not a concept SQL really has.

anyways, that sort of report output is something you usually do via your 
reporting code



In response to

pgsql-general by date

Next:From: Takahiro ItagakiDate: 2010-03-12 06:52:07
Subject: Re: [GENERAL] trouble with to_char('L')
Previous:From: A. KretschmerDate: 2010-03-12 06:13:35
Subject: Re: querying the value of the previous row

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group