Re: Sum - Mailing list pgsql-general

From Philip Hallstrom
Subject Re: Sum
Date
Msg-id 20020328092433.Y93259-100000@teak.adhesivemedia.com
Whole thread Raw
In response to Sum  (Marcelo Pereira <gandalf@sum.desktop.com.br>)
Responses Re: Sum  (Marcelo Pereira <gandalf@sum.desktop.com.br>)
List pgsql-general
I don't know of a SQL query that would do it, but you could do it in pgsql
or some other language... just run the normal query (the first one) and
then as you loop through the result set add 'value' to 'partial_sum' and
there you have it...

-philip

On Thu, 28 Mar 2002, Marcelo Pereira wrote:

> Hello All,
>
> I have a single table as:
>
> cod     date       value
> ---+-------------+-------
> 1  | 2002-03-12  |  5
> 2  | 2002-03-13  |  4
> 3  | 2002-03-13  |  7
> 4  | 2002-03-14  |  3
>
> ... and I would like to do a select that do `partial sums'.
>
> So, for instance, I would like to do a select that returns:
>
> cod     date       value   partial sum
> ---+-------------+-------+--------------
> 1  | 2002-03-12  |   5   |      5
> 2  | 2002-03-13  |   4   |      9
> 3  | 2002-03-13  |   7   |     16
> 4  | 2002-03-14  |   3   |     19
>
> As you can see, the row `partial sum' is what I am looking for. Do you
> have any idea how can I do it?
>
> Thanks in advance,
>
> Marcelo Pereira
>
> -- Remember that only God and Esc+:w saves.
>         __
>        (_.\           Marcelo Pereira       |
>         / / ___       marcelo@pereira.com   |
>        / (_/ _ \__    [Math|99] - IMECC     |
> _______\____/_\___)___Unicamp_______________/
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 5: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/users-lounge/docs/faq.html
>


pgsql-general by date:

Previous
From: "Steve Wolfe"
Date:
Subject: Re: Performance Tuning Document?
Next
From: "Johnson, Shaunn"
Date:
Subject: Re: table design strategy