Subject Re: [ib-support] Re: SQL: Number of entries per day
Author Arno Brinkman
Hi,

> I was thinking of returning a date and the number of entries on that
> day, i.e casting the timestamp using:
>
> CAST(TIME_STAMP as DATE)
>
> I've just tried:
>
> select CAST(ts as date), count(*) as entries
> from run_log
> group by CAST(ts as date)
> having entries > 0
>
> but it complains about the group by entry - 'Unknown toekn CAST'

Create a VIEW with EXTRACT and group by the VIEW columns.

CREATE VIEW Example1
(TableYear, TableMonth, TableDay) AS
SELECT
EXTRACT(YEAR FROM FieldX),
EXTRACT(MONTH FROM FieldX),
EXTRACT(DAY FROM FieldX)
FROM
ATable;

SELECT
TableYear,
TableMonth,
TableDay
FROM
Example1
GROUP BY
TableYear,
TableMonth,
TableDay

Ofcourse adding your missing fields.
Another way is creating computed by columns with EXTRACT() or UDF's.

Regards,
Arno