SQL Server: Rewrite query to support aggregate functions over aggregates/subqueries #34256
Labels
area-query
area-sqlserver
closed-fixed
The issue has been fixed and is/will be included in the release indicated by the issue milestone.
customer-reported
type-enhancement
Milestone
SQL Server has a limitation, where it doesn't allow aggregate functions invocations over other aggregate functions, or over subqueries; it errors with: "Cannot perform an aggregate function on an expression containing an aggregate or a subquery".
Examples:
The invalid SQL looks like this:
We should be able to have a post-processing step that lifts the subquery out of the projection, and integrates it into the SELECT expression as a OUTER APPLY (or CROSS JOIN, if uncorrelated):
Note that this affects non-GroupBy queries as well.
Full code
The text was updated successfully, but these errors were encountered: