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

Re: Compare rows

From: Thom Brown <thom(at)linux(dot)com>
To: LALIT KUMAR <lalit(dot)jss(at)gmail(dot)com>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: Compare rows
Date: 2011-07-13 08:30:25
Message-ID: CAA-aLv7Pa+j-c0sK_2KUVwHXvDP80-xH+3saKZZ6EJDLuow4jA@mail.gmail.com (view raw or flat)
Thread:
Lists: pgsql-novice
On 13 July 2011 07:15, LALIT KUMAR <lalit(dot)jss(at)gmail(dot)com> wrote:
> Hi,
> I have the following table.
> city    Rate         flag
> A         10             0
> A         20             1
> A         30              0
> A          2              0
> A         23              1
> A        12               0
> B          5               1
> B          43              0
> C         23                1
> C        67                 1
> For every city I have so set the  flag as -1 in row which is 0 above the row
> having flag as 1.
> So my out would be:
> city    Rate         flag
> A         10             -1
> A         20             1
> A         30              0
> A          2              -1
> A         23              1   (not changed to -1 as it not 0)
> A        12               0  (not changed to -1 because i need to compare
>  it to row of same city. so being last row not compared with any row)
> ----------------------------------------------------
> B          5               1
> B          43
> C         23                1
> C        67                 1

There doesn't appear to be any particular order to your rows.

-- 
Thom Brown
Twitter: @darkixion
IRC (freenode): dark_ixion
Registered Linux user: #516935

EnterpriseDB UK: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

In response to

Responses

pgsql-novice by date

Next:From: Oliveiros d'Azevedo CristinaDate: 2011-07-13 09:50:34
Subject: Re: Compare rows
Previous:From: LALIT KUMARDate: 2011-07-13 06:15:20
Subject: Compare rows

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