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 inner_query_name AS ( SELECT function(column_1) AS agg_column_1 FROM ... ) SELECT function(agg_column_1) FROM inner_query_name; - We can add a
GROUP BYclause in the outer query to show multi-level aggregation for multiple business objects:WITH inner_query_name AS ( SELECT function(column_1) AS agg_column_1, column_2 FROM ... ) SELECT function(agg_column_1) FROM inner_query_name GROUP BY column_2; - We can also use a
CASE WHENconstruction to introduce our own classifications into multi-level aggregations:WITH inner_query_name AS ( SELECT function(column_1) AS agg_column_1, CASE WHEN ... END AS column_2 FROM ... ) SELECT function(agg_column_1) FROM inner_query_name GROUP BY column_2; - Finally, we can use more than one CTE in a query:
WITH cte_1 AS (...), cte_2 AS (...), ..., cte_n AS (...) SELECT ...
Let's solve a few problems before we go...
Exercise
Click to continue.



