BeginnerCoder

Lesson 5 — COUNT & SUM

COUNT and SUM: one answer from many rows

An aggregate function combines many rows into a single value. COUNT(*) counts rows; SUM(column) adds up a column. You can rename a result with AS to make it readable.

SELECT COUNT(*) AS orders, SUM(total) AS revenue FROM orders

fetchone() returns the single result row as a tuple.

Why it matters: dashboards are mostly aggregates — number of users, total sales, orders today.

Want it another way?
Task

Write the query that returns COUNT(*) and SUM(total) from orders. Expected: (4, 100.0).

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.