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

compare date in two rows

From: LALIT KUMAR <lalit(dot)jss(at)gmail(dot)com>
To: pgsql-novice(at)postgresql(dot)org
Subject: compare date in two rows
Date: 2011-06-17 10:17:43
Message-ID: BANLkTi=gZbJW7+bNHPQnTPRPNnMGC2UucA@mail.gmail.com (view raw or flat)
Thread:
Lists: pgsql-novice
Hi,
I have a table with following sample data.

Village_name                       Date                  Label

A                                        1991-01-31            0

A                                        1991-04-28            0

A                                        1991-07-15            0

B                                        2000-02-15            0

B                                        2000-04-13            0

B                                        2001-09-13            0

C                                         1995-07-12           0

C                                         1995-10-13           0

I need to update the label to 1 when the number of days between two
dates(when compared with previous date)  is greater than 120 for each
village.

Illustration:
For village A: row 1 date will not be compared to any date.
                    row 2 date will be compared to row 1 date and if
satisfies the condition label will be made 1.
                    row 3 compare to row 2 and continue this till last row
for village A.

Similarly first date for  village B,C.

Responses

pgsql-novice by date

Next:From: Oliveiros d'Azevedo CristinaDate: 2011-06-17 11:10:33
Subject: Re: compare date in two rows
Previous:From: Jean-Yves F. BarbierDate: 2011-06-17 07:56:43
Subject: change p/w hashing

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