SQL-3: Aggregation
- ใช้ aggregate functions: COUNT, SUM, AVG, MIN, MAX
- จัดกลุ่มข้อมูลด้วย GROUP BY และกรองกลุ่มด้วย HAVING
- เข้าใจพฤติกรรมของ NULL ใน aggregation
- ใช้ COALESCE() จัดการค่า NULL
Progress 0 / 4
ทำไมต้อง Aggregation?
Section titled “ทำไมต้อง Aggregation?”ข้อมูลดิบหลายพันแถวไม่มีประโยชน์ถ้าไม่สรุป — Aggregation คือการเปลี่ยนข้อมูลหลายแถวให้กลายเป็นตัวเลขสรุปที่เข้าใจง่าย
ข้อมูลที่ใช้
Section titled “ข้อมูลที่ใช้”ตาราง students เดิม พร้อมข้อมูลเพิ่ม:
| student_id | name | price | enrolled_on | active | |
|---|---|---|---|---|---|
| STD001 | สมชาย | somchai@mail.com | 4500.00 | 2025-03-15 | TRUE |
| STD002 | สมหญิง | somying@mail.com | 3200.00 | 2025-06-01 | TRUE |
| STD003 | วิชัย | wichai@mail.com | 7800.00 | 2024-11-20 | FALSE |
| STD004 | มานี | manee@mail.com | 4500.00 | 2025-01-10 | TRUE |
| STD005 | กมล | NULL | 2100.00 | 2025-08-22 | FALSE |
| STD006 | ปรีชา | preecha@mail.com | 9500.00 | 2024-09-05 | TRUE |
บทเรียนในหมวดนี้
Section titled “บทเรียนในหมวดนี้” Aggregate Functions COUNT, SUM, AVG, MIN, MAX
GROUP BY จัดกลุ่มและกรองด้วย HAVING
NULL & Aggregation NULL ถูกจัดการอย่างไรใน aggregate
Lab: Business Questions ตอบคำถามธุรกิจด้วย aggregation