grouping by date increments

Поиск
Список
Период
Сортировка
Искать

grouping by date increments

От:
"Graham Vickrage" <graham@digitalplanit.com>
Дата:
Вложения:
I am trying to write a select statement to count the occurences of a
particular string between a set of dates.

I have written this successfully but need to get the count in time
increments such as per day/week/month.

At the moment I am doing a select for each increment seperately but figure
that as its doing a seqential scan then it may be possible to do it all at
once. 

Has anyone done anything similar that or maybe could recommend a more
efficient solution.

Thanks

Graham

current select:

SELECT to_char(timestamp('01-Jun-2000'), 'DD-Mon-YYYY'),
to_char(timestamp('01-Aug-2000'), 'DD-Mon-YYYY'), count(*) FROM table WHERE
date >= timestamp('01-Jun-2000') AND date < timestamp('01-Aug-2000') AND
text = 'FOOBAR';

Re: grouping by date increments

От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
"Graham Vickrage"  writes:
> I have written this successfully but need to get the count in time
> increments such as per day/week/month.

Perhaps use GROUP BY date_part(...).  See 
stgresql.org/devel-corner/docs/postgres/functions-datetime.htm
for doco on date_part().
		regards, tom lane

FAQ