| From: | Ketema Harris <ketema(at)gmail(dot)com> |
|---|---|
| To: | pgsql-general(at)postgresql(dot)org |
| Subject: | Grouping Question |
| Date: | 2009-07-31 16:09:51 |
| Message-ID: | C838FFD5-7C80-409E-A260-DAFD335DCFD7@midnightoilconsulting.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-general |
I have a table defined as
CREATE TABLE mytable
(
carrier varchar,
start_time timestamp with time zone,
call_date date,
cost numeric,
call_length numeric
)
I want to create a query that will generate a the following columns:
carrier, week, sum(call_length) as totallength, sum(cost) as total_cost
from mytable
group by carrier, (WHAT HERE?)
order by week, carrier
week is defined as a date range so something like 7/6/2009 - 7/13/2009
I would need the timestamps to be grouped into 7 day intervals
starting from the first one and moving through the table. is this
possible in a single query or would I have to write a function ?
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Raymond O'Donnell | 2009-07-31 16:12:02 | Re: export csv file on XP |
| Previous Message | Wang Kuo-Ying | 2009-07-31 15:58:05 | export csv file on XP |