Re: Grouping Question

Поиск
Список
Период
Сортировка
От Gerhard Heift
Тема Re: Grouping Question
Дата
Msg-id 20090731161732.GC3523@gheift.kawo1.rwth-aachen.de
обсуждение исходный текст
Ответ на Grouping Question  (Ketema Harris <ketema@gmail.com>)
Список pgsql-general
On Fri, Jul 31, 2009 at 12:09:51PM -0400, Ketema Harris wrote:
> 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:

select carrier,
extract(YEAR FROM start_time) || '-' || EXTRACT(WEEK FROM start_time),
sum(call_length) as totallength, sum(cost) as total_cost
from mytable
group by carrier,
extract(YEAR FROM start_time) || '-' || EXTRACT(WEEK FROM start_time),
order by carrier,
extract(YEAR FROM start_time) || '-' || EXTRACT(WEEK FROM start_time),
>
> 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 ?

Regards,
  Gerhard

Вложения

В списке pgsql-general по дате отправления:

Предыдущее
От: Gerhard Heift
Дата:
Сообщение: size of data stored in gist index
Следующее
От: Rob Wickert
Дата:
Сообщение: Re: Grouping Question