Overview

Course Overview β€” SQL Aggregation & Grouping Practice | DataSosi
Course Designer
Professor Mark Lokanan
Royal Roads University
Academic Director  ·  Canadian Institute of Artificial Intelligence (CiAI)
Architect of Next-Generation AI and Machine Learning Systems for Fraud Detection and Financial Crime Analytics
Course Overview · SQL Practice Series · Part 4

SQL Aggregation &
Grouping Practice

Summarizing, measuring, and comparing business performance — from individual aggregate functions through grouped category analysis and threshold filtering.

In real-world analytics, organizations constantly need to measure revenue, count customers, calculate averages, and compare performance across categories. Across seven parts, you will master MIN(), MAX(), COUNT(), SUM(), AVG(), GROUP BY, and HAVING — the aggregation and grouping toolkit that powers every business dashboard, KPI report, and executive summary. Same tables as Parts 1–3. Every query includes an AI prompt and a validated SQL answer.
7 Parts
56 Practice Queries
Same Tables as Parts 1–3
AI-Assisted Learning
Certificate of Completion

Course Learning Objectives

  • Use MIN() to identify the smallest values and earliest dates in business datasets.
  • Use MAX() to identify the largest values and most recent dates for peak and ceiling analysis.
  • Use COUNT() to measure operational volume and business activity across tables and filtered subsets.
  • Use SUM() to calculate total revenue, fees, quantities, and accumulated business metrics.
  • Use AVG() to calculate mean financial values and operational performance benchmarks.
  • Use GROUP BY to organise records into categories and produce grouped business summaries with aggregate functions.
  • Use HAVING to filter grouped summaries using aggregate conditions and business thresholds after GROUP BY.
Seven parts — click any part to see its topics and practice focus.
Floor Analysis

Part 1 covers MIN() — the function that returns the smallest value in a column. Students learn to apply MIN() to numeric columns for minimum prices, fees, and amounts; to date columns for the earliest dates; and to understand MIN() as an analytical baseline combined with ROUND() for clean financial output.

Topic 1
Lowest Business Values

Using MIN() to identify the floor of numeric business metrics β€” minimum amounts, prices, and fees.

Topic 2
Minimum Pricing

Finding the cheapest product, lowest subscription tier, and minimum transaction value.

Topic 3
Financial Minimums

Establishing minimum financial activity levels for benchmarking and threshold analysis.

Topic 4
Operational Baselines

Using MIN() on date columns to find the earliest signup, order, campaign, or ticket date.

  • Practice focus: minimum values and earliest dates across transactions, products, subscriptions, users, orders, campaigns, order_items, and support tickets
  • 8 practice queries — each with an AI prompt and a validated SQL answer
Ceiling Analysis

Part 2 covers MAX() — the complement of MIN(), returning the largest value in a column. Students learn to identify price maximums, revenue peaks, and the most recent dates using MAX(), and understand why reporting MIN() and MAX() together reveals the full range of a business metric.

Topic 1
Highest Business Values

Using MAX() to identify the ceiling of business metrics — maximum amounts, prices, and fees.

Topic 2
Maximum Pricing

Finding the most expensive product, highest subscription tier, and maximum transaction.

Topic 3
Revenue Peaks

Identifying peak financial activity and the highest single business metric value.

Topic 4
Operational Maximums

Using MAX() on date columns to find the latest signup, order, campaign end, or ticket date.

  • Practice focus: maximum values and latest dates across transactions, products, subscriptions, users, orders, campaigns, order_items, and support tickets
  • 8 practice queries — each with an AI prompt and a validated SQL answer
Volume Measurement

Part 3 covers COUNT() — the universal record counter. Students learn COUNT(*) for total row counts, COUNT(column) for non-NULL counts, and combining COUNT(*) with WHERE to measure filtered subsets like completed orders, active subscriptions, and open tickets.

Topic 1
Counting Records

COUNT(*) to measure total rows; COUNT(column) to count non-NULL values specifically.

Topic 2
Operational Totals

Measuring overall table volume as a first analytical step on any business dataset.

Topic 3
Customer Counts

Counting users, subscriptions, and activity records across the database.

Topic 4
Business Activity Measurement

Combining COUNT(*) with WHERE to count only records matching a business condition.

  • Practice focus: counting users, transactions, products, completed orders, active subscriptions, open tickets, Email campaigns, and Mobile sessions
  • 8 practice queries — each with an AI prompt and a validated SQL answer
Revenue Analysis

Part 4 covers SUM() — the function for calculating financial and operational totals. Students learn to calculate total revenue, subscription income, and sales values; combine SUM() with ROUND() for clean financial output; and use WHERE to sum only specific business subsets like Purchase or Active records.

Topic 1
Revenue Totals

SUM(amount) and SUM(monthly_fee) for total transaction and subscription revenue.

Topic 2
Financial Summaries

Building the total metrics that appear in P&L reports and executive dashboards.

Topic 3
Business Accumulation

SUM(quantity) and SUM(line_total) for total units sold and sales value from order items.

Topic 4
Total Operational Values

Combining SUM() with WHERE to total only Purchase, Refund, or Active records.

  • Practice focus: totalling amounts, fees, quantities, and sales values across transactions, subscriptions, and order items with WHERE filters
  • 8 practice queries — each with an AI prompt and a validated SQL answer
Mean Analysis

Part 5 covers AVG() — the function for calculating arithmetic means. Students learn to measure typical transaction values, average prices, mean fees, and average order sizes; combine AVG() with ROUND() for clean output; and use WHERE for segment-level averages like Purchase-only or Software-only means.

Topic 1
Average Calculations

AVG() on transaction amounts, product prices, and subscription fees for mean business metrics.

Topic 2
Mean Business Performance

Understanding typical performance values as a complement to SUM() and COUNT().

Topic 3
Customer Averages

Average order values and line totals for customer spending behaviour analysis.

Topic 4
Financial Averages

Segment-level averages using WHERE for Purchase, Active, and Software subsets.

  • Practice focus: average amounts, prices, fees, quantities, and order values across transactions, products, subscriptions, and order items with WHERE filters
  • 8 practice queries — each with an AI prompt and a validated SQL answer
Category Analysis

Part 6 covers GROUP BY — the command that unlocks category-level analysis. Students learn to combine GROUP BY with COUNT(), SUM(), and AVG() to produce one summary row per category, and understand the GROUP BY rule that governs which columns can appear in SELECT.

Topic 1
Grouped Business Summaries

Using GROUP BY with SUM() and COUNT() to produce category-level totals and counts.

Topic 2
Category-Level Analysis

Grouping by product category, order status, and subscription status for operational summaries.

Topic 3
Customer Segmentation

GROUP BY country and user_type for geographic and demographic business analysis.

Topic 4
Business Performance Grouping

Grouping campaigns by channel and sessions by device type for marketing analytics.

  • Practice focus: grouped totals and counts across transaction types, countries, product categories, order statuses, subscription statuses, ticket statuses, channels, and device types
  • 8 practice queries — each with an AI prompt and a validated SQL answer
Threshold Filtering

Part 7 covers HAVING — the clause that filters grouped summaries after GROUP BY has run. Students master the distinction between WHERE (filters rows) and HAVING (filters groups), and learn to apply business thresholds to COUNT(), SUM(), and AVG() results to surface only the groups that matter.

Topic 1
Filtering Grouped Results

HAVING applied after GROUP BY to keep only groups meeting a minimum condition.

Topic 2
Aggregate Filtering

Using HAVING with COUNT(), SUM(), and AVG() to apply threshold conditions to group totals.

Topic 3
Group-Level Conditions

The correct clause order: FROM → WHERE → GROUP BY → HAVING → ORDER BY → LIMIT.

Topic 4
Business Threshold Analysis

Identifying meaningful groups by filtering out low-volume or low-value categories.

  • Practice focus: HAVING thresholds on transaction types, product categories, countries, order statuses, subscription statuses, ticket statuses, channels, and device types
  • 8 practice queries — each with an AI prompt and a validated SQL answer

Course at a Glance

Seven parts · 56 practice queries · same tables as Parts 1–3

PartFunction / CommandCore FocusPractice
Part 1MIN()Smallest values and earliest dates — prices, fees, amounts, and date baselines8 Queries
Part 2MAX()Largest values and latest dates — revenue peaks, maximums, and most recent dates8 Queries
Part 3COUNT()Record counts and business volume — total and filtered row counts using WHERE8 Queries
Part 4SUM()Revenue totals and financial summaries — amounts, fees, quantities, and sales values8 Queries
Part 5AVG()Financial averages and benchmarks — mean amounts, prices, fees, and order values8 Queries
Part 6GROUP BYCategory-level grouped summaries — COUNT, SUM, AVG by type, status, and segment8 Queries
Part 7HAVINGThreshold filtering on grouped results — filtering after GROUP BY using aggregate conditions8 Queries
AI-Assisted SQL Learning

Every practice question in this course includes a business question, an AI prompt for ChatGPT or Copilot, the validated SQL answer, and guidance on interpreting the result. Students learn to prompt effectively, verify aggregation logic, troubleshoot GROUP BY and HAVING conditions, and connect summarized output to real business decisions.

What You Leave With

Seven aggregation and grouping commands. Fifty-six practice queries. A complete analytics reporting toolkit.

MIN()

The ability to identify the lowest prices, smallest amounts, and earliest dates in any dataset.

MAX()

The ability to identify revenue peaks, highest prices, and most recent dates for ceiling analysis.

COUNT()

Precise operational volume measurement — total and filtered record counts for every business table.

SUM()

Total revenue, subscription income, sales values, and accumulated operational metrics with ROUND().

AVG()

Mean financial values and segment-level benchmarks for pricing, spending, and performance analysis.

GROUP BY

Category-level grouped reports — the foundation of every business dashboard and KPI summary.

HAVING

Threshold filtering on grouped results — surfacing only the groups that meet meaningful business criteria.

Certificate

Certificate of Completion from the Canadian Institute of Artificial Intelligence (CiAI), powered by DataSoSi.