Lesson 31/100

Tutorials MySQL Tutorial

Grouped Aggregate Functions — Complete Guide

Grouped 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 31 of 100

Grouped Aggregate Functions

Basics ✓Advanced

Advanced · 2 — Production · ~6 min · MySQL — Functions & Window Functions

What is this?

Grouped aggregates combine GROUP BY with functions like SUM, AVG, COUNT per bucket. Filters on groups use HAVING; filters on raw rows use WHERE.

Why should you care?

Restaurant dashboard on Swiggy shows average delivery time per city — GROUP BY city, AVG(minutes).

See it live — copy this example

Run in MySQL Workbench or the mysql CLI.

SELECT c.city,
       COUNT(o.order_id) AS orders,
       SUM(o.total_inr) AS city_revenue
FROM customers c
JOIN orders o ON o.customer_id = c.customer_id
GROUP BY c.city
HAVING city_revenue >= 1000
ORDER BY city_revenue DESC;

What happened?

  • Join attaches orders to customer cities.
  • Aggregates compute per city.
  • HAVING drops cities under ₹1000 total revenue.

Practice next

  1. Seed multi-city customers and orders.
  2. Run query; verify math on one city manually.
  3. Move city filter to WHERE vs HAVING — note difference.
  4. Add AVG(o.total_inr) per city.
  5. GROUP BY city, DATE(o.placed_at) if date column exists.

Remember

GROUP BY + aggregates = per-bucket metrics. HAVING filters summarized rows. Mind JOIN grain to avoid inflated SUM.

DataFlow regional sales

Leadership sees city_revenue ranked for warehouse placement.

Outcome: Inventory moves to high-GMV cities.

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