(P)SQL for a sum with constraints

Поиск
Список
Период
Сортировка
От Shug Boabby
Тема (P)SQL for a sum with constraints
Дата
Msg-id 9508491d0904150309s3d2057a5rc1d81e9206a87ec6@mail.gmail.com
обсуждение исходный текст
Ответы Re: (P)SQL for a sum with constraints  (hubert depesz lubaczewski <depesz@depesz.com>)
Re: (P)SQL for a sum with constraints  ("A. Kretschmer" <andreas.kretschmer@schollglas.com>)
Список pgsql-general
Hello all,

I have a table with 2 bigint columns, let's call them A and B. I need
a query that will allow me to return A alongside the sum of Bs from
rows where A is less than or equal to this row's A. It is best
described with some example data, consider the following:

A B
1 0
2 1
3 0
4 2
5 1

I want to be able to make a query that returns the following rows:

A funkySumB
1 0
2 1
3 1
4 3
5 4

Anyone have any ideas how to do this? I'm able to do it
programmatically, but it's slow. Optimally I'd like to be able to do
this in the DB. As you can see, it's a little trickier that the usual
aggregate function with a GROUP BY and HAVING.

--
Shug

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

Предыдущее
От: Fujii Masao
Дата:
Сообщение: Re: PITR - warm standby switchover question
Следующее
От: hubert depesz lubaczewski
Дата:
Сообщение: Re: (P)SQL for a sum with constraints