Subject | Re: [firebird-support] Groupby on date |
---|---|
Author | Arno Brinkman |
Post date | 2004-11-09T18:19:37Z |
Hi,
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
> I have a table with a timestamp field. I need to do a count, and a sum ona
> field each and group by the month.the
>
> 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
> number of records grows this will be very slow? Is the best option then toIs the table growing and growing and you still want to group by month, not
> make a number, month field and keep this field up to date and indexed?
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