Errors in queries with derived tables

[CR #329454] Incorrect results may be returned for a query having more than one derived table with group by aggregates in the derived table expression.

Workaround: Do not run these types of queries.