Loading Depth Study
Preparing your workspace
Aggregate functions summarize multiple rows into useful calculated values.
COUNT, SUM, AVG, MIN, and MAX are common aggregate functions. GROUP BY groups rows that share a value so calculations can be performed separately for each group. HAVING filters grouped results after aggregation. These features are important for dashboards and analytics because they allow the database to calculate useful summaries instead of returning all raw records to the application.
A learning platform can count enrollments for each course and calculate the average score for each batch.
SELECT course_id, COUNT(*) AS enrollment_count, AVG(score) AS average_score FROM enrollments GROUP BY course_id HAVING COUNT(*) >= 5 ORDER BY enrollment_count DESC;
The query groups enrollments by course, calculates enrollment count and average score, and keeps courses with at least five enrollments.