Chapter 4 · 6 levels

Aggregates and GROUP BY

Turn rows into numbers: COUNT, SUM, AVG, MIN, MAX, then break them down by group with GROUP BY and filter groups with HAVING.

Start

This is the chapter where SQL starts producing the numbers people put in slides. “How many orders?”, “revenue per channel?”, “which customers ordered more than ten times?” are all aggregate queries.

You will learn the difference between COUNT(*), COUNT(column) and COUNT(DISTINCT column), how to compute revenue correctly from order lines, how GROUP BY splits a table into groups, and when a condition belongs in WHERE versus HAVING. The boss level is a performance snapshot with product, returns and conversion numbers.

Levels

  1. How many customers came from referrals?

    from Lauren Hayes, Email Marketing Manager

    count, count distinct, null, aggregates

    Code Difficulty 2 of 5 Not started

  2. Total units and revenue

    from Brian Mitchell, Finance Analyst

    sum, avg, min, max, revenue

    Code Difficulty 2 of 5 Not started

  3. Orders by channel and status

    from Megan Collins, Head of Sales

    group by, count, aggregates

    Code Difficulty 2 of 5 Not started

  4. Our most loyal customers

    from Megan Collins, Head of Sales

    having, where vs having, group by

    Code Difficulty 3 of 5 Not started

  5. Why does this query fail?

    from Tyler Morgan, Junior Data Engineer

    execution order, where vs having, aggregates

    Quiz Difficulty 3 of 5 Not started

  6. Boss: performance snapshot

    from Megan Collins, Head of Sales

    group by, sum, avg, having, conversion rate, top n

    Boss · 3 steps Difficulty 3 of 5 Not started