Rewriting calc queries to use subqueries

This fixes calcs on subform fields in many cases, however grouping is
broken because the group by clause is not being built the same, and/or
the handles it references need to be exposed in the outer query now.