Re: [SQL] Need to subtract values between previous and current row

2006-12-15 Thread Richard Broersma Jr
> not bad, except you miss the initial state for each cid, > and I do not see how you get the final duration. > cid | duration | state > -+--+--- > 101 |2 | 1 > 101 |2 | 2 > 101 |3 | 1 > 101 |3 | 2 > 102 |2 | 1 > 10

Re: [SQL] Need to subtract values between previous and current row

2006-12-15 Thread Ragnar
On fös, 2006-12-15 at 06:01 -0800, Richard Broersma Jr wrote: > > CIDATIME STATE > > 10112/10/2006 1 > > 10112/12/2006 2 > > 10112/14/2006 1 > > 10112/17/2006 2 > > 10212/14/2006 1 > > 10212/16/2006 2 > > 102

Re: [SQL] Need to subtract values between previous and current row

2006-12-15 Thread Richard Broersma Jr
> CIDATIME STATE > 10112/10/2006 1 > 10112/12/2006 2 > 10112/14/2006 1 > 10112/17/2006 2 > 10212/14/2006 1 > 10212/16/2006 2 > 10212/18/2006 3 select A.cid, (A.atime - max(B.atime)) duration, A.sta

Re: [SQL] Need to subtract values between previous and current row

2006-12-15 Thread Ragnar
On fös, 2006-12-15 at 19:21 +0600, Partha Guha Roy wrote: > Thanks for everyones email. Let me clarify a little bit more. > > Actually there is a state change of an entity. now the results are > stored in the following manner: > > CIDATIME STATE > 10112/10/2006 1 >

Re: [SQL] Need to subtract values between previous and current row

2006-12-15 Thread Partha Guha Roy
Hi, Thanks for everyones email. Let me clarify a little bit more. Actually there is a state change of an entity. now the results are stored in the following manner: CIDATIME STATE 10112/10/2006 1 10112/12/2006 2 10112/14/2006 1 10112/

Re: [SQL] Need to subtract values between previous and current row

2006-12-15 Thread Richard Broersma Jr
> > ID ATIME (MM/dd/) > == > 110/12/2006 > 210/14/2006 > 310/18/2006 > 410/22/2006 > 510/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 ide

Re: [SQL] Need to subtract values between previous and current row

2006-12-15 Thread Marc Mamin
I see 3 solutions. A) self join B) define a procedure that return a set of records. this use only a single table scan on the ordered table not tested, just the genera idea: CREATE OR REPLACE FUNCTION foo() RETURNS SETOF AS ... DELARE previous_time int8; --(or whaever da

Re: [SQL] Need to subtract values between previous and current row

2006-12-15 Thread Joe
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/) > == > 110/12/2006 > 210/14/2006 > 310/18/2006 > 410/22/2006 > 510/30/2006 > > No

Re: [SQL] Need to subtract values between previous and current row

2006-12-15 Thread Ragnar
On fös, 2006-12-15 at 18:27 +0600, Partha Guha Roy wrote: > Hi, > > I have a table that contains data like this: > > ID ATIME (MM/dd/) > == > 110/12/2006 > 210/14/2006 > 310/18/2006 > 410/22/2006 > 510/30/200

[SQL] Need to subtract values between previous and current row

2006-12-15 Thread Partha Guha Roy
Hi, I have a table that contains data like this: ID ATIME (MM/dd/) == 110/12/2006 210/14/2006 310/18/2006 410/22/2006 510/30/2006 Now I need a query that will subtract atime of row 1 from row 2, row2 from ro