Re: Sum raw with the same continuous flags

Поиск
Список
Период
Сортировка
От Andreas Kretschmer
Тема Re: Sum raw with the same continuous flags
Дата
Msg-id 20130601131707.GA28468@tux
обсуждение исходный текст
Ответ на Sum raw with the same continuous flags  (Shenli Zhu <zhushenli@gmail.com>)
Список pgsql-general
Shenli Zhu <zhushenli@gmail.com> wrote:

> Hi, there are 2 columns, flag(boolean) and num(integer),in a table.
> Table is like
> | flag | num |  
> |------+-----|
> |    1 |   2 | \ 5
> |    1 |   3 | /
> |    0 |   1 | \ 7
> |    0 |   6 | /
> |    1 |   4 | \ 9
> |    1 |   5 | /
> |  ... | ... |  
> I want to sum up the raw with the same continuous flags. E.g. flag in 1st and
> 2nd row are both 1, 3rd and 4th are both 0, 5th and 6th are both 1. So
> the table becomes
> | flag | num |
> |------+-----|
> |    1 |   5 |
> |    0 |   7 |
> |    1 |   9 |
>
> Can I do this in SQL or PL/pgSQL? Any suggestions are welcome.

You can do that in plain SQL (window-function, sum() over (...)), but i
think you needs an order-criteria to do that.



Andreas
--
Really, I'm not out to destroy Microsoft. That will just be a completely
unintentional side effect.                              (Linus Torvalds)
"If I was god, I would recompile penguin with --enable-fly."   (unknown)
Kaufbach, Saxony, Germany, Europe.              N 51.05082°, E 13.56889°


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

Предыдущее
От: Shenli Zhu
Дата:
Сообщение: Sum raw with the same continuous flags
Следующее
От: Kevin Grittner
Дата:
Сообщение: Re: Insert with query