Re: Date and filling issues

From: Rodrigo E(dot) De León Plicet <rdeleonp(at)gmail(dot)com>
To: "Christopher Crews" <isephoenix(at)yahoo(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Date and filling issues
Date: 2008-03-20 03:03:58
Message-ID: a55915760803192003i1acaa617x3644575772e7e030@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On 3/19/08, Christopher Crews <isephoenix(at)yahoo(dot)com> wrote:
> and what I'm trying to do is fill in the missing dates with sales values of 0.

create or replace function gen_dates(sd date, ed date)
returns setof date as $$
select $1 + i
from generate_series(0, $2 - $1) i;
$$ language sql immutable;

select d.date, sum(coalesce(sale_amount,0)) as sales
from gen_dates((current_date - interval '1 month')::date, current_date) d(date)
left join ej_transaction
on transaction_date=d.date
group by d.date
order by d.date asc;

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Gavin 'Beau' Baumanis 2008-03-20 09:57:53 Select into
Previous Message Tena Sakai 2008-03-20 02:45:02 Re: compare 2 tables in sql