Manuals / SQL / Chapter 6

B · Analyze · intermediate · Week 2 · Chapter 6 of 12

Aggregations & GROUP BY

COUNT, SUM, AVG, MIN, MAX. GROUP BY for per-category stats. HAVING filters groups after aggregation.

Path progress
44%

Step 1 of 3

Aggregates

COUNT(*), SUM(amount), AVG(price). Non-aggregated columns must appear in GROUP BY.

AggregatesDrag stickies · tap for tips
Study mapDrag stickies · tap for tipsKeep it shortdrag · tap →Name the waitdrag · tap →Scope locatorsdrag · tap →Trace when stuckdrag · tap →One browser firstdrag · tap →Isolate statedrag · tap →Assert the UIdrag · tap →Retry wiselydrag · tap →Seed datadrag · tap →Close the loopdrag · tap →Keep it shortdrag · tap →Name the waitdrag · tap →Scope locatorsdrag · tap →Trace when stuckdrag · tap →One browser firstdrag · tap →Isolate statedrag · tap →Pathwise hackdrag · tap →Aggregatesdrag · tap →Try thisdrag · tap →Follow the dashed drag · tap →

Example

SELECT
  COUNT(*) AS order_count,
  SUM(total) AS revenue,
  AVG(total) AS avg_order
FROM orders;

Do this now

Total revenue, order count, average order value from orders table.

Was this step clear?
Chapter learning outcomes
  • Aggregate functions
  • GROUP BY
  • HAVING vs WHERE
  • Query grain

Clear these before you leave

Side quest

Funnel counts

Group events by step_name; count users per step.