Lesson 19/100

Tutorials MySQL Tutorial

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

BasicsAdvanced

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

  1. Insert varied order totals including one NULL (if column allows).
  2. Run the aggregate SELECT.
  3. Compare COUNT(*) vs COUNT(total_inr) if NULLs exist.
  4. ROUND(AVG(total_inr), 2) for cleaner display.
  5. 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.

Junior Detailed
Explain SQL queries in the context of MySQL.
Short answer: Interviewers want a crisp definition, a practical example from your projects, and awareness of trade-offs—not textbook dumps. Explain a bit more How to structure your answer (60–90 seconds) Define SQL queri…
Mid Detailed
What are common mistakes teams make with Schema design when using MySQL?
Short answer: Interviewers want a crisp definition, a practical example from your projects, and awareness of trade-offs—not textbook dumps. Explain a bit more How to structure your answer (60–90 seconds) Define Schema de…
Senior Detailed
How would you debug a production issue related to Transactions in a MySQL application?
Short answer: Interviewers want a crisp definition, a practical example from your projects, and awareness of trade-offs—not textbook dumps. Explain a bit more How to structure your answer (60–90 seconds) Define Transacti…
Junior Detailed
Describe a real-world scenario where Normalization mattered in a MySQL project.
Short answer: Interviewers want a crisp definition, a practical example from your projects, and awareness of trade-offs—not textbook dumps. Explain a bit more How to structure your answer (60–90 seconds) Define Normaliza…
Questions on this lesson 0

Sign in to ask a question or upvote helpful answers.

No questions yet — be the first to ask!

MySQL Tutorial
Course syllabus

MySQL Tutorial

MySQL — Foundations
MySQL — Queries & Clauses
MySQL — Joins & Relationships
MySQL — Functions & Window Functions
MySQL — Transactions & Concurrency
MySQL — Stored Procedures & Triggers
MySQL — Indexing & Performance
MySQL — Advanced MySQL
MySQL — Security & Cloud MySQL
MySQL — Real-World Projects
Toolliyo Assistant
Ask about tutorials, ebooks, training, pricing, mentor services, and support. I use public site content only—not admin or internal tools.

care@toolliyo.com

Need callback? Share your details