Re: Getting running totals - Mailing list pgsql-novice

From David
Subject Re: Getting running totals
Date
Msg-id 20050408211820.GC920@localhost.localdomain
Whole thread Raw
In response to Re: Getting running totals  (Bob Henkel <luckyratfoot@gmail.com>)
List 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@simpaticus.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.]

pgsql-novice by date:

Previous
From: David
Date:
Subject: Re: Getting running totals
Next
From: "Rodolfo J. Paiz"
Date:
Subject: Re: Getting running totals