Subject Re: [firebird-support] Groupby on date
Author Arno Brinkman
Hi,

> I have a table with a timestamp field. I need to do a count, and a sum on
a
> field each and group by the month.
>
> I know I can use extract to get the month and group by that, but I am
> assuming that in such a case FB will not be able to use an index and as
the
> number of records grows this will be very slow? Is the best option then to
> make a number, month field and keep this field up to date and indexed?

Is the table growing and growing and you still want to group by month, not
depending on what year it is?
Anyway i don't think a index on the month field will help much (read: it
will be worser). A index on the timestamp field will probably be the best,
assuming you want group by month over a certain period.

SELECT
EXTRACT(MONTH FROM FieldTimeStamp),
Count(*),
Sum(Field1),
Sum(Field2),
Sum(Field3),
Sum(Field4)
FROM
TableX
WHERE
FieldTimeStamp >= '2003-01-01' and
FieldTimeStamp < '2004-01-01'
GROUP BY
1

Regards,
Arno Brinkman
ABVisie

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Firebird open source database (based on IB-OE) with many SQL-99 features :
http://www.firebirdsql.org
http://www.firebirdsql.info
http://www.fingerbird.de/
http://www.comunidade-firebird.org/

Support list for Interbase and Firebird users :
firebird-support@yahoogroups.com

Nederlandse firebird nieuwsgroep :
news://80.126.130.81