Subject RE: [firebird-support] Re: How to eliminate long GROUP BY?
Author Leyne, Sean
> martin.agren wrote:
> > I have often asked myself why the group by syntax is so ineffective.
> >
> > Couldnt a short hand (non standard) addition be
> >
> > Select grouped Description, count(Id) Count
> >
> > All that is required is a new keyword, that internally picks all non
> > aggregate columns and adds them to a group by statement.
> >
> > The obvious benefit would of course appear when we have a large
number
> > of those non aggregate columns.
>
> Neat idea perhaps, but 1) it would be better to get this keyword into
> the standard than to have a non-standard thing in FB, and 2) the
> original poster wasn't primarily complaining about too much typing but
> risk of hitting the max sort key size, which your suggestions doesn't
> help.

Another option is the use the Derived Table functionality:

SELECT
Table.Field1
Table.Field2
Table.Field3
...
GroupData.Field2
GroupData.RowCount
FROM (
SELECT
FK.field1
SUM( Field2) as Field2
COUNT(*) as RowCount
FROM
DetailTable
GROUP BY 1
) as GroupData
JOIN Table on Table.Key = GroupData.Field1


Sean