Received: from localhost (maia-4.hub.org [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id 5733A9F9B05 for ; Fri, 15 Dec 2006 09:04:42 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-new, port 10024) with ESMTP id 17714-07-2 for ; Fri, 15 Dec 2006 09:04:33 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from vms042pub.verizon.net (vms042pub.verizon.net [206.46.252.42]) by postgresql.org (Postfix) with ESMTP id 74E0C9FA1FD for ; Fri, 15 Dec 2006 09:04:33 -0400 (AST) Received: from [192.168.7.5] ([71.101.14.69]) by vms042.mailsrvcs.net (Sun Java System Messaging Server 6.2-6.01 (built Apr 3 2006)) with ESMTPA id <0JAB00H1OGB1QAS7@vms042.mailsrvcs.net> for pgsql-sql@postgresql.org; Fri, 15 Dec 2006 07:04:14 -0600 (CST) Date: Fri, 15 Dec 2006 08:05:35 -0500 From: Joe Subject: Re: Need to subtract values between previous and current row In-reply-to: <6bdfe880612150427o19bfe90ch87a972c0f5898ffb@mail.gmail.com> To: Partha Guha Roy Cc: pgsql-sql@postgresql.org Message-id: <1166187935.691.2.camel@pampa> Organization: Freedom Circle, LLC MIME-version: 1.0 X-Mailer: Evolution 2.8.2.1 FreeBSD GNOME Team Port Content-type: text/plain Content-transfer-encoding: 7bit References: <6bdfe880612150427o19bfe90ch87a972c0f5898ffb@mail.gmail.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200612/111 X-Sequence-Number: 27067 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