pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Joe <dev@freedomcircle.net>
To: Partha Guha Roy <partha.guha.roy@gmail.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: Need to subtract values between previous and current row
Date: Fri, 15 Dec 2006 08:05:35 -0500
Message-ID: <1166187935.691.2.camel@pampa> (raw)
In-Reply-To: <6bdfe880612150427o19bfe90ch87a972c0f5898ffb@mail.gmail.com>
References: <6bdfe880612150427o19bfe90ch87a972c0f5898ffb@mail.gmail.com>

On Fri, 2006-12-15 at 18:27 +0600, Partha Guha Roy wrote:
> I have a table that contains data like this:
> 
> 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...
> 
> Can anyone please help?

How about something like this

select x.id, x.atime, x.atime - y.atime as diff
from yourtable x, yourtable y
where x.id + 1 = y.id;

Joe




view thread (10+ messages)  latest in thread

Message-ID: <1166187935.691.2.camel@pampa>
Permalink:  ../1166187935.691.2.camel@pampa/
Also on:    postgresql.org/message-id/1166187935.691.2.camel@pampa

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: dev@freedomcircle.net, partha.guha.roy@gmail.com
  Subject: Re: Need to subtract values between previous and current row
  In-Reply-To: <1166187935.691.2.camel@pampa>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox