When the Output Is a Pivot-Like Summary
Concepts covered: sqlConditionalAgg
What conditional aggregation actually does A normal aggregate (SUM, COUNT, AVG) operates on every row in the group. A conditional aggregate operates on every row in the group but only counts the ones matching the CASE condition. SUM(CASE WHEN status='active' THEN 1 ELSE 0 END) counts active rows. SUM(CASE WHEN status='active' THEN amount ELSE 0 END) sums amounts from active rows. The CASE inside the aggregate filters what contributes to the sum, while the row itself stays in the group. This is what lets one query produce multiple slice columns in the same row. Spotting the pattern in the first ten seconds Read the question. If the output has 'count of X' and 'count of Y' and 'sum of Z' all in the same row of output, you need conditional aggregation. The trigger words: 'broken down by,' 'sp
About This Interactive Section
This section is part of the Conditional Aggregation: Beginner lesson on DataDriven, a free data engineering interview prep platform. Each section includes explanations, worked examples, and hands-on code challenges that execute in real time. SQL queries run against a live database. Python runs in a sandboxed Docker container. Data modeling problems validate against interactive schema canvases. All content is framed around what data engineering interviewers actually test at companies like Meta, Google, Amazon, Netflix, Stripe, and Databricks.
How DataDriven Lessons Work
DataDriven combines four interview rounds (SQL, Python, Data Modeling, Pipeline Architecture) with adaptive difficulty and spaced repetition. Easy problems get harder as you improve. Weak concepts resurface until you master them. Your readiness score tracks progress across every topic interviewers test. Every lesson section ends with problems you solve by writing and running real code, not by picking multiple-choice answers.