Re: Sum raw with the same continuous flags

Поиск
Список
Период
Сортировка
От David Johnston
Тема Re: Sum raw with the same continuous flags
Дата
Msg-id 1370097746415-5757671.post@n5.nabble.com
обсуждение исходный текст
Ответ на Re: Sum raw with the same continuous flags  (Victor Yegorov <vyegorov@gmail.com>)
Список pgsql-general
Виктор Егоров wrote
> 2013/6/1 Shenli Zhu <

> zhushenli@

> >
>
>> 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.

What you want to do is possible and you have been provided some resources to
do so.  However, with the table you have provided it is not possible to
implement such a solution.  Tables do not have "order" to them inherently.
You must decide on a mechanism to distinguish between the "1"s in the first
group and the "1"s in the second group and code your query to ORDER BY using
that mechanism before assigning group identifiers and performing the group
sub-total.

This is not an optional requirement.  If you query works without doing that
you are simply lucky and at some point in the future it can possibly stop
working which means that you query is broken/buggy.

Since your example looks made-up you are on your own for the "mechanism" but
if time can be used you can possibly get away with either an "serial" column
or a "current timestamp" column to enforce the order.

David J.





--
View this message in context:
http://postgresql.1045698.n5.nabble.com/Sum-raw-with-the-same-continuous-flags-tp5757658p5757671.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.


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

Предыдущее
От: David Johnston
Дата:
Сообщение: Re: Strange behavior of "=" as assignment operator
Следующее
От: Tom Lane
Дата:
Сообщение: Re: Strange behavior of "=" as assignment operator