From: Dani Oderbolz <oderbolz@ecologic.de>
To: Erik Thiele <erik@thiele-hydraulik.de>
To: pgsql-sql@postgresql.org
Subject: Re: summing tables
Date: Tue, 15 Jul 2003 14:17:50 +0200
Message-ID: <3F13F0EE.8040700@ecologic.de> (raw)
In-Reply-To: <20030715140921.7c5a6a6c.erik@thiele-hydraulik.de>
References: <20030715140921.7c5a6a6c.erik@thiele-hydraulik.de>
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
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: oderbolz@ecologic.de, erik@thiele-hydraulik.de
Subject: Re: summing tables
In-Reply-To: <3F13F0EE.8040700@ecologic.de>
* 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