Re: cumulative count

From: David Fetter <david(at)fetter(dot)org>
To: Carson Farmer <carson(dot)farmer(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: cumulative count
Date: 2008-12-04 19:21:45
Message-ID: 20081204192145.GB20693@fetter.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Thu, Dec 04, 2008 at 05:53:06PM +0000, Carson Farmer wrote:
> Hi list,
>
> This is my first post to pgsql, so hopefully I'm not asking something
> that has been answered a thousand time before. I've looked online, and
> through the archives, but I haven't found anything that answers my
> question specifically:
>
> Say I have a table like this:
>
> date | user
> ------------------+---------------------
> 20050201 | Bill
> 20050210 | Steve
> 20050224 | Sally
> 20050311 | Martha
> 20050316 | Ryan
> 20050322 | Phil
> 20050330 | William
> 20050415 | Mary
> 20050428 | Susan
> 20050503 | Jim
>
> and I want to run a query that returns a *count* of the number of users
> *each month*, ordered by year and *month*, with an additional column
> that is a *running total of the count*, as in:

In 8.4, you'll have direct SQL support for this using OLAP a.k.a.
windowing functions, so don't build too many of these dodgy hacks into
your application.

Cheers,
David.
--
David Fetter <david(at)fetter(dot)org> http://fetter.org/
Phone: +1 415 235 3778 AIM: dfetter666 Yahoo!: dfetter
Skype: davidfetter XMPP: david(dot)fetter(at)gmail(dot)com

Remember to vote!
Consider donating to Postgres: http://www.postgresql.org/about/donate

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Jason Long 2008-12-04 22:54:38 Re: Job scheduling in Postgre
Previous Message Pavel Stehule 2008-12-04 19:16:50 Re: cumulative count