58. All Combinations with CUBE
Difficulty: Hard · Topics: Pivot, Unpivot & Rollup, Aggregations, Conditional Logic
An advanced problem: unlock it to open the statement, sample data and editor. Graded on 3 test cases.
Learn the concepts
- rollup / cube · 4 min read. Subtotals and grand totals in one pass, and how grouping() tells a total row from a real null.
- when / otherwise · 4 min read. CASE WHEN logic inside a column: first match wins, and a missing otherwise means null.
- withColumn · 6 min read. Add or replace one column, and why calling it in a long loop slows Spark down.
PySpark functions you'll practise
- agg
- sum
- count
- cube
- grouping_id
- when / otherwise
- withColumn
Related problems
- Subtotals with ROLLUP · Hard · Pivot, Unpivot & Rollup, Aggregations, Conditional Logic, Filtering & Selection
- Pivot with Several Aggregations · Hard · Pivot, Unpivot & Rollup, Aggregations, Null Handling
- Survey Scores by Question · Medium · Pivot, Unpivot & Rollup, Aggregations
- Pivot Quarterly Revenue · Medium · Pivot, Unpivot & Rollup, Aggregations
- Unpivot Wide Columns to Rows · Medium · Pivot, Unpivot & Rollup, Null Handling, Filtering & Selection
Browse
Topics: Window Functions · Joins · Aggregations · Pivot, Unpivot & Rollup · Arrays · Null Handling · Conditional Logic · Dates · Filtering & Selection · Strings · Data Lake · Lakehouse · Streaming · Data Prep for AI · Spark Performance
Difficulty: Easy · Medium · Hard · Learn · All problems · dbt practice