SQL aggregate functions help you summarize the data in a table. For example, you can count products, find their average price or add up the prices of products in a set.
COUNT counts rows, SUM adds values, AVG calculates the average, and MIN and MAX find the minimum and maximum.
Our examples use the candy table. The price field contains the price, and filling indicates whether the candy has a filling.
- COUNT
- SUM, AVG, MIN, MAX
- GROUP BY: group rows
- HAVING: filter groups by a condition
| id | name | filling | price |
|---|---|---|---|
| 1 | Plutonian Praline | true | 30 |
| 2 | Explosive Comet | true | 60 |
| 3 | Universal Harmony | false | 20 |
| 4 | Pluto's Tears | false | 40 |
| 5 | Mint Vortex | false | 40 |
| 7 | Plutonic Cream | false | 70 |
| 10 | Pluto Mystery | true | 90 |
The candy table