Subject Re: CAST or GROUP BY error... or is this week becoming too long for me :)
Author Alexander V.Nevsky
--- In ib-support@y..., "Martijn Tonies" <m.tonies@u...> wrote:
> Hi,
> > I have a dialect 3 database (FB 1) with a table that has a
TIMESTAMP
> > column (fecha). I executed the following query:
> >
> > SELECT CAST(fecha AS DATE) AS fecha
> > FROM telefono
> > GROUP BY fecha;
> >
> > I would expect a result set of unique dates, but instead I recieve
> > repeated rows. How come?
>
> You are grouping by the original column (fecha), not by the alias.
The
> GROUP BY of Firebird 1 can only group on existing columns.

Hi, All. It's again me with my box of hacks ;) Looking through this
thread I see grouping by Extract(something From TimeStamp) is
discussed. FB1 really can't group by internal functions but it can
group by UDF! How do you think, is it important what is the argument
of UDF? Naturally, no. So, for example

Select Some_Aggregate, Abs(Extract (Year From TimeStamp)),
Abs(Extract (Month From TimeStamp)),
Abs(Extract (Day From TimeStamp))
From ...
Where ...
Group By Abs(Extract (Year From TimeStamp)),
Abs(Extract (Month From TimeStamp)),
Abs(Extract (Day From TimeStamp))

will work and save us from great headache :)))

Best regards, Alexander V.Nevsky.