BeginnerCoder

Lesson 10 — Aggregations

Summaries of many records

An aggregation turns many records into one number: a count, a sum, an average. In Django: Order.objects.aggregate(Sum("amt")). In Python, sum() and len() do the same on a list.

sum(p["qty"] for p in items)   # total

The average is just total divided by count.

Note: the exercise runs in your browser without Django installed, so it is a small plain-Python simulation of what Django does for you.

Why it matters: dashboards and reports are mostly aggregations — revenue, number of users, average order.

Want it another way?
Task

Print the number of orders, the total amount and the average amount.

Run your code — when the output matches the task, you will see a green check. Then mark the lesson complete.

← Back
Next →
Test your knowledge

A quick 3-question quiz on this lesson — instant feedback.

Enjoying this lesson? Share it.