From: | "Chad Wagner" <chad(dot)wagner(at)gmail(dot)com> |
---|---|
To: | "John Summerfield" <postgres(at)herakles(dot)homelinux(dot)org> |
Cc: | pgsql-sql(at)postgresql(dot)org |
Subject: | Re: How to aggregates this data |
Date: | 2007-01-11 00:38:38 |
Message-ID: | 81961ff50701101638v68f96965y2310a152d71f3d9@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
By the way, if you want to include that "incomplete" week before 12/1
(incomplete because it doesn't have a data point for Monday) then you would
do this:
select s1.asx_code, s1.wdate AS date, s1.low, s1.high, s2.open, s3.close,
s1.volume
from (select asx_code, date_trunc('week', date) AS wdate, min(date) AS
bdate, max(date) AS edate, min(low) AS low, max(high) AS high, SUM(volume)
AS volume
from sales_summaries
group by asx_code, date_trunc('week', date)) s1, sales_summaries s2,
sales_summaries s3
where s1.bdate = s2.date
and s1.asx_code=s2.asx_code
and s1.edate = s3.date
and s1.asx_code=s3.asx_code;
From | Date | Subject | |
---|---|---|---|
Next Message | Marc Mamin | 2007-01-11 08:29:56 | a way to generate functions dynamically ? |
Previous Message | Chad Wagner | 2007-01-11 00:29:41 | Re: How to aggregates this data |