COUNT, SUM, and AVG are aggregate functions.
COUNT returns a count of the number of data values.
SUM returns the sum of the data values.
AVG returns the average of the data values.
For a list of all aggregate functions see our aggregate functions reference.
Get the total number of products.
SELECT COUNT(Id) AS 'Product Count'
FROM Product
| Product Count |
|---|
| 78 |
COUNT syntax.
SELECT COUNT(column-name) FROM table-name
SUM syntax.
SELECT SUM(column-name) FROM table-name
AVG syntax.
SELECT AVG(column-name) FROM table-name
| CUSTOMER |
|---|
| Id |
| FirstName |
| LastName |
| City |
| Country |
| Phone |
SELECT COUNT(Id) AS 'Customer Count'
FROM Customer
| Customer Count |
|---|
| 91 |
| ORDER |
|---|
| Id |
| OrderDate |
| OrderNumber |
| CustomerId |
| TotalAmount |
SELECT SUM(TotalAmount) AS 'Total Sales'
FROM [Order]
WHERE YEAR(OrderDate) = 2013
| Total Sales |
|---|
| 658388.75 |
| ORDER |
|---|
| Id |
| OrderDate |
| OrderNumber |
| CustomerId |
| TotalAmount |
SELECT AVG(TotalAmount) AS 'Avg Order'
FROM [Order]
| Avg Order |
|---|
| 1631.877819 |