Re: Sum

From: Marcelo Pereira <gandalf(at)sum(dot)desktop(dot)com(dot)br>
To: Philip Hallstrom <philip(at)adhesivemedia(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Sum
Date: 2002-03-28 17:29:52
Message-ID: Pine.LNX.4.20.0203281427170.13785-100000@ni.hmmg.sp.gov.br
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hello Philip,

I am using PHP to show the results in a html file, and I have this
`partial sum' running the same way you told. I am just looking around to
know if I can do this straight from a sql query, without any type of
external script, as I am already doing.

Thanks for you answer.

Best Regards,

Marcelo Pereira

-- Remember that only God and Esc+:w saves.
__
(_.\ Marcelo Pereira |
/ / ___ |
/ (_/ _ \__ Matematica/99 - IMECC |
_______\____/_\___)___Unicamp_______________/

--- Philip Hallstrom, with his fast fingers, wrote:

:> 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(at)pereira(dot)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
:> >
:>

In response to

  • Re: Sum at 2002-03-28 17:25:22 from Philip Hallstrom

Browse pgsql-general by date

  From Date Subject
Next Message Matthew Kirkwood 2002-03-28 17:37:43 Re: Performance Tuning Document?
Previous Message Johnson, Shaunn 2002-03-28 17:28:40 Re: table design strategy