Re: need some help on figuring out how to write a query

Поиск
Список
Период
Сортировка
От Jorge Godoy
Тема Re: need some help on figuring out how to write a query
Дата
Msg-id 200802220921.33034.jgodoy@gmail.com
обсуждение исходный текст
Ответ на need some help on figuring out how to write a query  (Justin <justin@emproshunts.com>)
Ответы Re: need some help on figuring out how to write a query
Список pgsql-general
Em Thursday 21 February 2008 18:37:47 Justin escreveu:

> Now i could write a function to do this or do it in C++ program that
> creates query with all kinds of unions.  I'm wondering if there is a way
> to create this in a single select statement??
> I can't think of a way to do it???

Why you need it in one query?  Think of maintenability not on code size.

Solve the problem in parts, calculating it for one week -- or ten, you can use
the interval type -- and then moving on...

The function would look like:

WHILE start_date + '10 weeks'::interval < today:
    SELECT INTO weeks_avg avg(value) FROM table WHERE date BETWEEN start_date AND
start_date+'10 weeks'::interval;
    start_date:=start_date + '1 week'::interval;
END WHILE;


Start from that and you'll have it done.  (Of course, above is pseudo code and
untested...)

--
Jorge Godoy      <jgodoy@gmail.com>


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

Предыдущее
От: Jorge Godoy
Дата:
Сообщение: Re: PostgreSQL 8.3.0 RPMs are available for download
Следующее
От: Oleg Bartunov
Дата:
Сообщение: Re: ts_headline