Subject Re: [ib-support] GROUP BY ON MONTH or YEAR of DATE FIELDS
Author Lucas Franzen
"enricorav " schrieb:
>
> Hi to all,
> there are some methods for make a SELECT with GROUP BY on a part of a
> DATE or TIMESTAMP fields?
> Something like this:
>
> SELECT ...
> FROM MY_TABLE
> ...
> GROUP BY MONTH(DATE_REG), YEAR(DATE_REG)
>
> where DATE_REG are a DATE fields or TIMESTAMP fields ?

Create a view that Extracts the Month / Year from the date fields then
you can do the
SELECT .. GROUP BY from this view.

CREATE VIEW V_MYVIEW ( REG_M, REG_Y )
AS
SELECT
EXTRACT ( MONTH FROM DATE_REG ) AS REG_M,
EXTRACT ( YEAR FROM DATE_REG ) AS REG_Y
FROM MY TABLE


Then you can group by these fields:

SELECT COUNT (*), REG_M, REG_Y
FROM MY V_MYVIEW
GROUP BY REG_M, REG_Y


Luc.