Received: from localhost (maia-1.hub.org [200.46.204.191]) by postgresql.org (Postfix) with ESMTP id 393A49FA474 for ; Fri, 15 Dec 2006 10:01:35 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.191]) (amavisd-new, port 10024) with ESMTP id 14977-09 for ; Fri, 15 Dec 2006 10:01:30 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.4 Received: from web31802.mail.mud.yahoo.com (web31802.mail.mud.yahoo.com [68.142.207.65]) by postgresql.org (Postfix) with SMTP id 607299FA3AD for ; Fri, 15 Dec 2006 10:01:30 -0400 (AST) Received: (qmail 75088 invoked by uid 60001); 15 Dec 2006 14:01:28 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=X-YMail-OSG:Received:Date:From:Subject:To:Cc:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding:Message-ID; b=RYf+/Ax25yt6cBf6rxEiVxzusZTRvAltebjC/LDJ3aLixijf+iDnK6lWblBcEB+9nIk4wYNusAHq9fL/RRTuRbQgmkcQPO6r9eyBOcAj4ju+Uv1zPIgi2wLVCYjsS/AmjJ2rBc5bM2dC80f3MEkB1EEvaFTZ5+K5LI3pMJLfvbM=; X-YMail-OSG: x_zLbY0VM1mG6BXhb6.5YOOqhM55ZmKvIH8I6E9DXxn2YuA1H8AmlPRxxNQfl7pkly8I9dlDzrVF7GmpuN6MmGBYEL8TLTuZqUjqXllXS5B9BtgxTbMsqJG2Pl4BK4Y8 Received: from [75.84.83.178] by web31802.mail.mud.yahoo.com via HTTP; Fri, 15 Dec 2006 06:01:28 PST Date: Fri, 15 Dec 2006 06:01:28 -0800 (PST) From: Richard Broersma Jr Subject: Re: Need to subtract values between previous and current row To: Partha Guha Roy Cc: pgsql-sql@postgresql.org In-Reply-To: <6bdfe880612150521n137d80f7q463955f26db1cef0@mail.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Message-ID: <519101.72709.qm@web31802.mail.mud.yahoo.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=1.619 tagged_above=0 required=5 tests=AWL, BAYES_05, DNS_FROM_RFC_ABUSE, DNS_FROM_RFC_POST, DNS_FROM_RFC_WHOIS X-Spam-Level: * X-Archive-Number: 200612/116 X-Sequence-Number: 27072 > 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;