In IB Computer Science, SQL is not only used to retrieve individual records, but also to summarise data. This is done using aggregate functions. These functions allow databases to calculate totals, averages, and counts efficiently, even when working with very large datasets.
IB examiners expect students to understand what aggregate functions do, why they are useful, and how they change the type of result returned.
What Are Aggregate Functions?
Aggregate functions perform a calculation on multiple records and return a single value.
Instead of listing individual records, they:
- Summarise data
- Provide statistical insight
- Reduce large datasets into meaningful information
In IB terms, aggregate functions are used for data analysis, not data retrieval.
COUNT Explained
The COUNT function returns the number of records that match a condition.
COUNT is used to:
- Find how many records exist
- Measure frequency
- Count entries that meet criteria
For example, COUNT can be used to:
- Count the number of students
- Count how many orders were placed
- Count records matching a WHERE condition
Important IB concept:
- COUNT does not return the data itself
- It returns a single numerical value
