Subquery with aggregates