SELECT:
*Selecting with Aggregate functions
AVG() aggregate function will return the average of values selected.
SELECT AVG(Salary) FROM Employees
SELECT AVG(Salary) FROM Employees where DepartmentId = 1
If employee is categorized with multiple department and we want to find avg salary for every department then we can use following query.
SELECT AVG(Salary) FROM Employees GROUP BY DepartmentId
MIN() aggregate function will return the minimum of values selected.
SELECT MIN(Salary) FROM Employees
MAX() aggregate function will return the maximum of values selected.
SELECT MAX(Salary) FROM Employees
COUNT() aggregate function will return the count of values selected.
SELECT Count(*) FROM Employees
SELECT Count(*) FROM Employees where ManagerId IS NOT NULL
NULL values are not counted.
Select Count(ManagerId) from Employees
Select Count(DISTINCT DepartmentId) from Employees
SUM() aggregate function returns the sum of the values selected for all rows.
SELECT SUM(Salary) FROM Employees