Sum of multiplied deltas

From: Gerhard Wiesinger <lists(at)wiesinger(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Sum of multiplied deltas
Date: 2009-06-08 06:35:20
Message-ID: alpine.LFD.2.00.0906080831290.13493@bbs.intern
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hello!

I've the following data:
datetime | val1 | val2
time1 | 4 | 40%
time2 | 7 | 30%
time3 | 12 | 20%
...

I'd like to sum up the following:

(7-4)*30% + (12-7)*20% + ...

datetime is ordered (and unique and has also an id).

Rows are in the area of millions.

How is it done best?
1.) Self join with one row shift?
2.) function?

Any hint?

Thnx.

Ciao,
Gerhard

--
http://www.wiesinger.com/

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Sebastien FLAESCH 2009-06-08 07:20:29 Re: INTERVAL SECOND limited to 59 seconds?
Previous Message Anirban Pal 2009-06-08 05:57:51 Why lots of temp schemas are being created