Re: Breakdown results by month

From: Bruno Wolff III <bruno(at)wolff(dot)to>
To: Henry Ortega <juandelacruz(at)gmail(dot)com>
Cc: Pgsql-sql(at)postgresql(dot)org
Subject: Re: Breakdown results by month
Date: 2005-08-10 17:52:29
Message-ID: 20050810175229.GA2525@wolff.to
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Tue, Aug 02, 2005 at 14:34:46 -0400,
Henry Ortega <juandelacruz(at)gmail(dot)com> wrote:
> I have the ff table:
>
> id | total | effective | end_date
> john 6 01-01-2005 02-28-2005
> john 8 03-01-2005 06-30-2005
>
> How can I return:
> id | total | effective | end_date
> john 6 01-01-2005 01-31-2005
> john 6 02-01-2005 02-28-2005
> john 8 03-01-2005 03-31-2005
> john 8 04-01-2005 04-30-2005
> john 8 05-01-2005 05-31-2005
> john 8 06-01-2005 06-30-2005
>
> Any help would be appreciated. Thanks

One approach would be to generate the monthly dates using generate_series
and some date math and join those rows to your ff table where the generated
dates are covered by the effective and end dates in the ff table. You may
need some more trickery if some of the dates aren't on month boundries.

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message nori 2005-08-10 22:45:24 How to alias table columns in result?
Previous Message Owen Jacobson 2005-08-10 16:27:23 Re: **SPAM** Faster count(*)?