Re: Sum of multiplied deltas

Поиск
Список
Период
Сортировка
От Oliver Kohll - Mailing Lists
Тема Re: Sum of multiplied deltas
Дата
Msg-id 28E9499F-8D69-432E-B81E-5E198803918D@gtwm.co.uk
обсуждение исходный текст
Ответ на Sum of multiplied deltas  (Gerhard Wiesinger <lists@wiesinger.com>)
Ответы Re: Sum of multiplied deltas  ("Marc Mamin" <M.Mamin@intershop.de>)
Список pgsql-general
On 8 Jun 2009, at 19:01, David Fetter wrote:

>> 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% + ...
>
> This is best done in 8.4 using Windowing.  Sadly, it's an 8.4-only
> feature, and dodgy hacks are the rule until you can use them.
>
> Cheers,
> David.
>


I do this type of thing now and again using a self join with an offset.

select test_a.val1 - test_b.val1
from test test_a inner join test test_b
on test_a.pkey = test_b.pkey - 1;

Thought I was quite clever the first time, didn't know it was a dodgy
hack! I'm trying to learn more about windowing before 8.4, how would
this example be done with that?

Regards
Oliver

В списке pgsql-general по дате отправления:

Предыдущее
От: Ioana Danes
Дата:
Сообщение: Re: Duplicate key issue in a transaction block
Следующее
От: Oliver Kohll - Mailing Lists
Дата:
Сообщение: Re: [pgsql-general] Daily digest v1.9081 (14 messages)