Re: Need to subtract values between previous and current row

From: Richard Broersma Jr <rabroersma(at)yahoo(dot)com>
To: Partha Guha Roy <partha(dot)guha(dot)roy(at)gmail(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Need to subtract values between previous and current row
Date: 2006-12-15 14:01:28
Message-ID: 519101.72709.qm@web31802.mail.mud.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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;

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Ragnar 2006-12-15 16:06:56 Re: Need to subtract values between previous and current row
Previous Message Ragnar 2006-12-15 13:40:25 Re: Need to subtract values between previous and current row