From: | Dani Oderbolz <oderbolz(at)ecologic(dot)de> |
---|---|
To: | Erik Thiele <erik(at)thiele-hydraulik(dot)de>, pgsql-sql(at)postgresql(dot)org |
Subject: | Re: summing tables |
Date: | 2003-07-15 12:17:50 |
Message-ID: | 3F13F0EE.8040700@ecologic.de |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
Erik Thiele wrote:
>hi,
>
>i have a table consisting of 4 integers.
>
>seq is for making the table ordered. (ORDER BY SEQ ASC)
>a,b,c maybe null
>
>
> seq | a | b | c
>-----+----+----+---
> 0 | 1 | 2 | 3
> 1 | 1 | 2 |
> 2 | 5 | 7 |
> 3 | -2 | -4 |
>
>
>i am needing a sql statement to do
>
>c=a+b+"the c of the row with seq one less than myself"
>
>this statement has to run over the whole table, in seq order.
>
>
>how can this be acomplished???
>
>
>cu&thanks
>erik
>
>
>
>
Hi Erik,
this should do the trick:
(I have not yet considered the NULLS though...)
UPDATE table t set c = a + b + (Select c from table tt where tt.seq =
t.seq -1)
Cheers, Dani
From | Date | Subject | |
---|---|---|---|
Next Message | Erik Thiele | 2003-07-15 12:39:25 | Re: summing tables |
Previous Message | Viorel Dragomir | 2003-07-15 12:16:21 | Re: summing tables |