update from multiple rows

From: "adam etienne" <a_eti(at)hotmail(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: update from multiple rows
Date: 2005-01-22 12:51:20
Message-ID: BAY13-F384058140ADAAD16F8BE889830@phx.gbl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

hi
I have some trouble updating a table like this one :
date | data_raw | data_sys
12-01 | 5 | 4.5
13-01 | 6 | 6
14-01 | 7 | 8

I would like to update the 'data_sys' row by computing values of multiple
'data_raw' values. I mean for example :
data_sys(13-01) = (data_raw['12-01'] + data_raw['13-01'] +
data_raw['14-01'] )/3;

I thought of a function that fetch the 3 data_raw rows for each rows....
but it was obviously too much slow...

Is there a more efficient way to achieve this ?
Thanks in advance.. This could help me very much..

Etienne Adam

_________________________________________________________________
無料メールならやっぱり 「MSN Hotmail」 http://www.hotmail.com/

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Kretschmer Andreas 2005-01-22 15:56:11 Question about a select
Previous Message TJ O'Donnell 2005-01-22 00:51:19 testing/predicting optimization using indexes