Am 11.09.2013 um 17:31 schrieb Andrew Dunstan <andrew@dunslane.net>:
> I recently had to diagnose and remedy a case such as this.
>
> The short answer is to rewrite your query so you don't have to group by so many things. Collect your aggregates in a
commontable expression query (or possibly more than one, depends what you need) using the minimum non-aggregated
columnsto enable you to get correct results and then later decorate that with all the extra things you need such as
constantcolumns and columns that are irrelevant to the aggregation.
>
> This gets hard when queries are very complex, and harder still when the query is written by a query generator. But a
goodgenerator should not just say "grouo by everything that's not aggregated" and think it's doing a good job. In your
caseit should be relatively straightforward.
>
> cheers
>
> andrew
Ah, yes, only now do I see that the query screams for a CTE. Thanks for the eye opener.
Maximilian Tyrtania
http://www.contactking.de