Re: Need to subtract values between previous and current row - Mailing list pgsql-sql

From Richard Broersma Jr
Subject Re: Need to subtract values between previous and current row
Date
Msg-id 519101.72709.qm@web31802.mail.mud.yahoo.com
Whole thread Raw
In response to Re: Need to subtract values between previous and current row  ("Partha Guha Roy" <partha.guha.roy@gmail.com>)
Responses Re: Need to subtract values between previous and current row  (Ragnar <gnari@hive.is>)
List pgsql-sql
> CID        ATIME          STATE
> 101        12/10/2006     1
> 101        12/12/2006     2
> 101        12/14/2006     1
> 101        12/17/2006     2
> 102        12/14/2006     1
> 102        12/16/2006     2
> 102        12/18/2006     3

select A.cid, (A.atime - max(B.atime)) duration, A.state
from table A join table B
on (A.atime > B.atime and A.cid = B.cid)
group by A.atime, A.cid, A.state;



pgsql-sql by date:

Previous
From: Ragnar
Date:
Subject: Re: Need to subtract values between previous and current row
Next
From: Ragnar
Date:
Subject: Re: Need to subtract values between previous and current row