Queries containing a select statement with a group by statement

[CR #333077] Queries containing a select with a group by with a case expression using a local variable, may return wrong results.

Workaround: Remove the use of the local variable in group by.