An aggregated expression containing an outer reference must be contained in either the select list, or a HAVING clause subquery ...