Published lesson · 30 minutes

Combine and summarize records

Objective: Use an aggregate function and GROUP BY to compare counts or totals for each category.

Understand the idea

Combine and summarize records works best when the learner can explain the reason behind each step, not just copy a result. Aggregate functions reduce many rows to a summary; `GROUP BY` defines which rows belong together before the summary is calculated.

A synthetic stock table can show how many items are available in each category without revealing individual records. Treat the names and details as invented practice information; the example is for learning a method and does not describe a live service.

A dependable sequence is: Choose the measure, group by a clear category and give each calculated column a descriptive alias. Write down the important decision before you begin so another person can follow the reasoning.

Check whether null values or duplicated rows change the total. A summary should answer a stated question, not imply more precision than its sample data supports. Compare the result with the objective, then change one thing at a time if the first attempt does not work.

Add one sample row and predict which grouped total should change. Explain one assumption that would need checking before anyone used a similar result outside the classroom.

Keep a short record of the choices you made and the evidence you used to check them. A useful practice result is understandable by another learner, stays within the stated scope and makes its limitations visible before anyone relies on it.

Worked examples

Combine and summarize records: practice example

Explore how combine and summarize records supports the lesson objective with a small synthetic example.

inventory.sql

CREATE TABLE stock_moves (category TEXT, quantity INTEGER);
INSERT INTO stock_moves VALUES ("books", 4), ("books", 3), ("tools", 2);
SELECT category, SUM(quantity) AS available FROM stock_moves GROUP BY category ORDER BY category;

Practice tasks

  1. Explore combine and summarize records

    Use the worked example for “Combine and summarize records”. Change one small detail to suit a different synthetic community situation, then explain what you expected and how you checked whether the change still met the lesson objective.

  2. Build a SQL practice example

    Create a small practice result that demonstrates this objective: Use an aggregate function and GROUP BY to compare counts or totals for each category. Use only synthetic information, keep the first version focused, and write down one limitation that a later version should address.

  3. Review and explain the result

    Review your “Combine and summarize records” result as if another learner will use it without your explanation. Identify one strength, one exact point that may be unclear, and a revision that would make the result easier to understand or use.

Combine and summarize records becomes easier when you choose the measure, check the result and explain the choice to another learner.

Course overview