Improve handling of subqueries in an aggregate query

The columns of the aggregate query, particularly those in the GROUP BY clause, might appear in the subquery. As will columns from tables inside the subquery itself. The former need to be mapped to columns from the aggregate operator. The latter are left alone, like columns from outer queries were already. See new test case for an example.