Select Count, AVG, SUM
The COUNT() function returns the number of rows.
The AVG() function returns the average value of a column.
The SUM() function returns the total sum of a column.
SQL Select COUNT() Syntax:
SELECT COUNT(Column1)
FROM Table_Name
WHERE condition;
SQL Select AVG() Syntax:
SELECT AVG(Column1)
FROM Table_Name
WHERE condition;
SQL Select SUM() Syntax:
SELECT SUM(Column1)
FROM Table_Name
WHERE condition;
Example:
Lets use the following table to count the number of Products from the SupplierName column with the name of ‘TechOne’.
Results:
Now lets find the average price of Products from the SupplierName column with the name of ‘TechOne’.
SELECT AVG(Price) as Result
FROM Products
WHERE SupplierName = ‘TechOne’
Results:
Finally lets find the sum price of Products from the SupplierName column with the name of ‘TechOne’.
Results:
SQL Tutorial