PySpark Aggregations
36 interview problems on groupBy, agg, percentiles and conditional metrics, from easy to hard.
Learn Aggregations
- groupBy + agg · 4 min read. Aggregate rows per group: counts, sums, averages, and how count(*) differs from count(col).
- max_by / min_by · 4 min read. Return the value from the row where another column is largest or smallest, in one aggregate.
- percentile_approx · 4 min read. Medians and p90s that scale to billions of rows, and how the accuracy setting trades memory for error.
- collect_list / collect_set · 4 min read. Gather the values of a group into an array, with or without duplicates, and in which order.
- Average Salary by Department · Easy · Aggregations
- Departments with Large Teams · Easy · Aggregations, Filtering & Selection
- Find Repeat Customers · Easy · Aggregations, Filtering & Selection
- Find Partitions That Need Compaction · Easy · Data Lake, Aggregations, Filtering & Selection
- Live Page View Counts · Easy · Streaming, Aggregations
- Conditional Aggregation · Medium · Aggregations, Conditional Logic
- Entry and Exit Pages (MAX_BY / MIN_BY) · Medium · Aggregations
- New Users per Day · Medium · Aggregations
- Median and 90th Percentile · Medium · Aggregations
- Word Count · Medium · Arrays, Aggregations, Strings, Filtering & Selection
- Sorted Distinct Purchase List · Medium · Arrays, Aggregations
- Learning Path per Student · Medium · Arrays, Aggregations, Strings, Filtering & Selection
- Pivot Quarterly Revenue · Medium · Pivot, Unpivot & Rollup, Aggregations
- Survey Scores by Question · Medium · Pivot, Unpivot & Rollup, Aggregations
- How Much Does Each Query Read? · Medium · Data Lake, Joins, Aggregations
- Inventory a Partitioned Folder · Medium · Data Lake, Aggregations, Strings
- Find Files Spark Cannot Split · Medium · Data Lake, Aggregations, Conditional Logic
- Late Data in the Raw Zone · Medium · Data Lake, Aggregations, Dates
- Rebuild a Table from Its Transaction Log · Medium · Lakehouse, Joins, Aggregations
- Files VACUUM Can Delete · Medium · Lakehouse, Joins, Aggregations
- Iceberg Hidden Partition Layout · Medium · Lakehouse, Aggregations, Dates
- Click Counts in 5-Minute Windows with Late Data · Medium · Streaming, Aggregations, Filtering & Selection
- Hourly Revenue per Store, Updated Live · Medium · Streaming, Aggregations, Filtering & Selection
- Split Train and Test With No User in Both · Medium · Data Prep for AI, Joins, Aggregations
- Conversion Funnel · Hard · Aggregations, Conditional Logic
- Fill Missing Dates (Calendar Spine) · Hard · Joins, Arrays, Aggregations, Dates, Null Handling, Filtering & Selection
- Customers Who Bought Every Product · Hard · Joins, Aggregations, Filtering & Selection
- Monthly Retention by Cohort · Hard · Joins, Aggregations, Dates, Null Handling, Filtering & Selection
- Three-Day Login Streak · Hard · Window Functions, Aggregations, Dates, Filtering & Selection
- Consecutive Status Runs (Gaps and Islands) · Hard · Window Functions, Aggregations
- Subtotals with ROLLUP · Hard · Pivot, Unpivot & Rollup, Aggregations, Conditional Logic, Filtering & Selection
- All Combinations with CUBE · Hard · Pivot, Unpivot & Rollup, Aggregations, Conditional Logic
- Pivot with Several Aggregations · Hard · Pivot, Unpivot & Rollup, Aggregations, Null Handling
- Find Hot Keys and Plan Salting · Hard · Spark Performance, Joins, Aggregations
- Net Changes from a Change Feed · Hard · Lakehouse, Aggregations, Conditional Logic
- Trending Searches in Sliding Windows · Hard · Streaming, Aggregations, 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