Lesson 2 of 13 · 16 min
SUM, AVG, MIN and MAX
By the end of this lesson you can summarise numeric, date and text columns with SUM, AVG, MIN and MAX, aggregate an expression such as quantity × price, and round the result correctly.
COUNT tells you how many. The other four everyday aggregates tell you how much and how far:
| function | returns | works on |
|---|---|---|
SUM(x) | the total of x | numbers |
AVG(x) | the arithmetic mean of x (total ÷ number of values) | numbers |
MIN(x) | the smallest x | numbers, dates, timestamps, text |
MAX(x) | the largest x | numbers, dates, timestamps, text |
Like COUNT, they read every row that survives WHERE and return a single value. You can put several of them in one SELECT list; each is computed over the same set of rows.
This lesson, its 4 graded exercises and every other Members lesson in SQL Quest come with a Formula Quest membership that includes SQL (Single Quest with SQL selected, Quest Trio including SQL, or Quest Unlimited), or with SQL access from your organization.
Free to everyone: all of SQL Foundations and Retrieving and Filtering Data, the first lesson of every track, the playground, the dataset library and the SQL reference. See free lessons