SQL Server Tutorial
Let us consider the example 'Employee' database table.
In SQL Server, AVG function is used to calculate average value based on numeric column, constants or expression.
SELECT AVG([ALL | DISTINCT] expression) FROM table_name WHERE Filter_condition
Computing average salary in SELECT Statement using AVG function.
SELECT AVG(Salary) 'Average Salary' FROM EmployeeOutput:
Computing average salary in SELECT Statement using AVG function with DISTINCT Keyword.
SELECT AVG(DISTINCT Salary) 'Average Salary' FROM EmployeeOutput:
Computing average salary in SELECT Statement using AVG function with ALL Keyword.
SELECT AVG(ALL Salary) 'Average Salary' FROM EmployeeOutput:
In SQL Server, COUNT function is used to get number of rows and parameter can be *, numeric column, constants or expression.
SELECT COUNT ([ALL | DISTINCT] expression) FROM table_name WHERE Filter_condition
Computing number of rows based on all the columns from Employee table in SELECT Statement using COUNT function.
SELECT COUNT(*) 'Rows Count' FROM EmployeeOutput:
Computing number of rows based on Id column from Employee table in SELECT Statement using COUNT function.
SELECT COUNT(Id) 'Rows Count' FROM EmployeeOutput:
Computing number of rows based on Salary column from Employee table in SELECT Statement using COUNT function.
SELECT COUNT(DISTINCT Salary) 'Rows Count' FROM EmployeeOutput:
Computing number of rows based on Salary column from Employee table in SELECT Statement using COUNT function.
SELECT COUNT(ALLSalary) 'Rows Count' FROM EmployeeOutput:
In SQL Server, MAX function is used to get the maximum value based on column or expression.
SELECT MAX (expression) FROM table_name WHERE Filter_condition
Computing maximum value based on column or expression from Employee table in SELECT Statement using MAX function.
SELECT MAX(Salary) 'Maximum Salary' FROM EmployeeOutput:
In SQL Server, MIN function is used to get the minimum value based on column or expression.
SELECT MIN(expression) FROM table_name WHERE Filter_condition
Computing minimum value based on column or expression from Employee table in SELECT Statement using MIN function.
SELECT MIN(Salary) 'Minimum Salary' FROM EmployeeOutput:
In SQL Server, SUM function is used to calculate sum value based on numeric column, constants or expression.
SELECT SUM([ALL | DISTINCT] expression) FROM table_name WHERE Filter_condition
Computing sum salary in SELECT Statement using SUM function.
SELECT SUM(Salary) 'Total Salary' FROM EmployeeOutput:
Computing sum of salary's in SELECT Statement using SUM function with DISTINCT Keyword.
SELECT SUM(DISTINCT Salary) 'Total Salary' FROM Employee Output:SUM Function with ALL
Computing average salary in SELECT Statement using SUM function with ALL Keyword.
SELECT SUM(ALL Salary) 'Total Salary' FROM Employee Output:
« Previous Next »
SQL Server Tutorial
Privacy Policy | Copyright2020 - All Rights Reserved. | Contact us | Report website issues in Github | Facebook page | Google+ page