Aggregate Functions — Complete Guide
Aggregate Functions — Complete Guide: free step-by-step lesson with examples, common mistakes, and interview tips — part of MySQL Tutorial on Toolliyo Academy.
On this page
MySQL Tutorial · Lesson 19 of 100
Aggregate Functions
Basics → Advanced
Basics · 1 — SQL · ~6 min · MySQL — Queries & Clauses
What is this?
Aggregates collapse many rows into one value: COUNT, SUM, AVG, MIN, MAX. They power dashboards and invoices.
Why should you care?
Swiggy’s daily GMV is SUM(order_total) for today — one number executives watch, not raw row export.
See it live — copy this example
Run in MySQL Workbench or the mysql CLI.
SELECT
COUNT(*) AS order_count,
SUM(total_inr) AS revenue_inr,
AVG(total_inr) AS avg_order_inr,
MIN(total_inr) AS smallest,
MAX(total_inr) AS largest
FROM orders;
What happened?
- One result row summarizes the whole orders table.
- SUM and AVG ignore NULL totals if any.
- MIN/MAX show range of cart sizes for DataFlow.
Practice next
- Insert varied order totals including one NULL (if column allows).
- Run the aggregate SELECT.
- Compare COUNT(*) vs COUNT(total_inr) if NULLs exist.
- ROUND(AVG(total_inr), 2) for cleaner display.
- Use IFNULL(SUM(total_inr),0) when no rows match WHERE.
Remember
Aggregates return single summary values. COUNT(*) counts rows; SUM/AVG work on numbers. Filter with WHERE before aggregating when possible.
DataFlow daily revenue tile
CEO dashboard runs one aggregate query every morning for yesterday’s SUM(total_inr).
Outcome: Finance trusts SQL numbers over spreadsheet exports.
Interview prep for this lesson
Practice these questions aloud after reading—each links to a full structured answer.
Sign in to ask a question or upvote helpful answers.
No questions yet — be the first to ask!