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>, pgsql-sql(at)postgresql(dot)org
Subject: Re: Need to subtract values between previous and current row
Date: 2006-12-15 13:12:01
Message-ID: 297264.3730.qm@web31806.mail.mud.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

>
> ID ATIME (MM/dd/yyyy)
> == ====
> 1 10/12/2006
> 2 10/14/2006
> 3 10/18/2006
> 4 10/22/2006
> 5 10/30/2006
>
> Now I need a query that will subtract atime of row 1 from row 2, row2 from
> row3 and so on...

just an idea.

select (A.atime - max(B.atime)) duration
from table A join table B
on (A.atime > B.atime)
group by A.atime;

Regards,
Richard Broersma Jr.

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Partha Guha Roy 2006-12-15 13:21:36 Re: Need to subtract values between previous and current row
Previous Message Marc Mamin 2006-12-15 13:06:29 Re: Need to subtract values between previous and current row