গল্প — কেন Aggregate?
E-commerce-এ ১০ লাখ order। CEO জিজ্ঞেস করে: মোট order কত? Total sales? Average? Highest? Lowest?
CEO কি ১০ লাখ row দেখতে চায়? নাকি ছোট summary report?
Real-life Examples
School
Total / Average / Highest / Lowest marks · কতজন student?
Company
Total / Average / Highest / Lowest salary · headcount
Hospital
Patients · average age · max/min age
Bank
Total deposits · avg transaction · max/min
Aggregate Function কী?
Aggregate Function = একাধিক row-এর data নিয়ে একটি summary result তৈরি করে।
৫টি Core Function
employees Dataset
COUNT(*)
COUNT(*) = কয়টি row আছে।
COUNT(column) vs COUNT(*)
COUNT(DISTINCT)
SUM()
AVG()
MAX()
MIN()
Comparison Table
| Function | Meaning | Example |
|---|---|---|
| COUNT() | কতটি | কতজন employee? |
| SUM() | মোট | মোট salary? |
| AVG() | গড় | Average salary? |
| MAX() | সর্বোচ্চ | Highest salary? |
| MIN() | সর্বনিম্ন | Lowest salary? |
Aggregate vs Normal
Multiple Aggregates (no GROUP BY)
GROUP BY + COUNT
GROUP BY = কোন কলাম অনুযায়ী আলাদা আলাদা দল বানাও।
GROUP BY + SUM
GROUP BY + AVG
GROUP BY + MAX
প্রতি department-এর মধ্যে highest।
GROUP BY + MIN
Full Department Report
Aggregate + WHERE
Aggregate + HAVING
WHERE vs HAVING
| WHERE | HAVING |
|---|---|
| Row filter | Group filter |
| Before grouping | After grouping |
| Individual records | Summary groups |
| Usually before GROUP BY | After GROUP BY |
WHERE
HAVING
NULL + Aggregates
DISTINCT + Aggregate
Unique customers / cities / categories count করতে ব্যবহার।
Aggregate + ORDER BY / LIMIT
E-commerce KPIs
E-com + GROUP BY
Business Questions → SQL (১৫)
Aggregation Animation
Guess the Output
Choose the Function
Common Mistakes (১৫)
- SUM দিয়ে count
- COUNT দিয়ে money
- AVG ও SUM গুলিয়ে
- GROUP BY ভুলে
- Non-grouped column SELECT
- WHERE vs HAVING গুলিয়ে
- NULL = 0 ভাবা
- COUNT(col) যখন COUNT(*) চাই
- DISTINCT ভুলে
- MAX দিয়ে পুরো row চাওয়া
- MIN ভুল ব্যবহার
- Wrong GROUP column
- Alias না দেওয়া
- Business Q না বুঝে function
- Aggregate সবসময় ১ row — GROUP BY থাকলে নয়
Execution Flow
No GROUP BY
With GROUP BY
Aggregate vs GROUP BY
Single vs Multiple Groups
Industry Use
- Analytics / BI: KPI, sales, dashboards
- Finance: revenue, expense, profit
- HR: headcount, salary cost
- Data Science: feature / behavior summaries
- Data Engineering: ETL batch summaries, DQ counts
Mini Project — Employee Dashboard
- Highest employee count dept
- Highest salary cost dept
- Highest average salary dept
- Depts with >5 employees
- Depts with avg salary > 50000
Advanced Beginner — CASE
Aggregates + Dates
Multi-column GROUP BY
Performance Basics
Interview Top 30
MCQ (২৫+)
Viva
Classroom Exercises (২০)
Homework Project
E-commerce Sales Analytics Report
- Overall: COUNT, SUM, AVG, MAX, MIN, unique customers/cities/categories
- Category analysis: orders, sales, avg, max, min
- City analysis: orders, sales, AOV
- HAVING: sales>100000 · cities>20 orders
- Dashboard query: all five aggs + GROUP BY + WHERE/HAVING/ORDER/LIMIT
1-Minute Revision
Final Memory Map
SQL AGGREGATE
COUNT / SUM / AVG / MAX / MIN
↓
GROUP BY → Create Groups → Aggregate → HAVING → Report
RAW DATA → Many Rows → Need Summary → AGGREGATE
→ (GROUP BY if separate summaries)
→ WHERE / HAVING → ORDER BY / LIMIT → BUSINESS REPORT
Aggregate Function = অনেকগুলো row-এর data নিয়ে summary information তৈরি করে।