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 297264.3730.qm@web31806.mail.mud.yahoo.com
Whole thread Raw
In response to 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
List 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.


pgsql-sql by date:

Previous
From: "Marc Mamin"
Date:
Subject: Re: Need to subtract values between previous and current row
Next
From: "Partha Guha Roy"
Date:
Subject: Re: Need to subtract values between previous and current row