Summer Deals - hours only!Up to 80% off on all courses and bundles.-Close
Introduction
Basic multi-level aggregation
Multi-level aggregation in groups
Multi-level aggregation with custom classification
Three or more aggregation levels
Summary
15. Summary

Instruction

Good job! Now, let's wrap things up. First, here's a summary of what we've covered in this part:

  1. 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;
    
  2. We can add a GROUP BY clause 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;
    
  3. We can also use a CASE WHEN construction 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;
    
  4. 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 Next exercise to continue.