Introduction to Aggregate Functions
Explore the aggregation functions available in MySQL.
In SQL, we are used to seeing statements being applied to a table on a row-by-row basis. Doing so makes sense given the nature of SQL’s logical layer where data is stored in tables. Data retrieval using simple SELECT [...] FROM [...] WHERE [...];
statement is convenient this way. Our mental model fails when we want to operate on a set of rows. MySQL provides different constructs for these kinds of operations. Aggregate functions are among the most comprehensive and can be integrated seamlessly into our existing knowledge of SQL statements.
Operating on sets of values
Before looking at examples of aggregate functions, we want to rehearse our understanding of operating on sets of rows instead of rows alone. Let us consider the following table that consists of a single column with the data type SMALLINT
populated with a number:
Get hands-on with 1400+ tech skills courses.