Re: Getting running totals

From: David <dbree(at)duo-county(dot)com>
To: Bob Henkel <luckyratfoot(at)gmail(dot)com>
Cc: "Rodolfo J(dot) Paiz" <rpaiz(at)simpaticus(dot)com>, David <dbree(at)duo-county(dot)com>, pgsql-novice(at)postgresql(dot)org
Subject: Re: Getting running totals
Date: 2005-04-08 21:18:20
Message-ID: 20050408211820.GC920@localhost.localdomain
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

On Fri, Apr 08, 2005 at 12:11:25PM -0500, Bob Henkel wrote:
> This is just psuedo code but what about this approach...
> SELECT ,
> CASE WHEN MONTH='JANUARY' THEN 1
> WHEN MONTH='OCTOBER THEN 10
> ELSE 999999
> END
> FROM test;
> Then order by the value of the case statement to get the months in the
> correct order.

I'd thought about something like this, too, but my goal is to eliminate
as much programming as possible and let SQL do the work. I got it to
work by creating a view to do the grouping, and then having another view
call up that view and then sort on the column. However, so far, Tom
Lane showed me how to do it in a single command. Also, Rodolfo has
verified some of my assumtions. Thanks to all for the replies.

> On Apr 8, 2005 10:40 AM, Rodolfo J. Paiz <rpaiz(at)simpaticus(dot)com> wrote:
> >
> > On Thu, 2005-04-07 at 22:00 -0500, David wrote:
> > > This may be another elementary question - I found some hints in the
> > > archives that may have answered my question, but not sure..
> > >
> >
> > That's OK... I just had another elementary problem similar to yours
> > (been using SQL for less than a month or so), so allow me to share the
> > solutions or workarounds that I used.
> >
> > > I'm designing a database to maintain business records. I'd like to
> > > get an output like so:
> > >
> > > Month | Month Ttl | Year-to-Date
> > > -------+-----------+--------------
> > > Jan | 25.00 | 25.00
> > > Feb | 25.00 | 50.00
> > > Mar | 50.00 | 100.00
> > > Apr | 50.00 | 150.00
> > > (4 rows)

[question was about sorting et.al.]

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message DavidF 2005-04-08 21:40:32 Re: Getting running totals
Previous Message Tom Lane 2005-04-08 21:13:56 Re: Interval Precision