Instruction
Good job! Now, let's wrap things up. First, here's a summary of what we've covered in this part:
- Multi-level aggregations require common table expressions (CTEs). The most basic CTE looks like this:
WITH InnerQueryName AS ( SELECT Function(Column1) AS AggColumn1 FROM ... ) SELECT Function(AggColumn1) FROM InnerQueryName; - We can add a
GROUP BYclause in the outer query to show multi-level aggregation for multiple business objects:WITH InnerQueryName AS ( SELECT Function(Column1) AS AggColumn1, Column2 FROM ... ) SELECT Function(AggColumn1) FROM InnerQueryName GROUP BY Column2; - We can also use a
CASE WHENconstruction to introduce our own classifications into multi-level aggregations:WITH InnerQueryName AS ( SELECT Function(Column1) AS AggColumn1, CASE WHEN ... END AS Column2 FROM ... ) SELECT Function(AggColumn1) FROM InnerQueryName GROUP BY Column2; - Finally, we can use more than one CTE in a query:
WITH Cte1 AS (...), Cte2 AS (...), ..., CteN AS (...) SELECT ...
Let's solve a few problems before we go...
Exercise
Click to continue.



