T-SQL Aggregate Function – Syntax and Example

SQL Aggregate Function is built-in functions for counting and calculation (perform a calculation on a set of values and return a single value)
Syntax for built-in SQL functions is –
SELECT function(column) FROM table

Name Salary
Emil 5000
Chang 5000
Emily 4500
Nick 4000

Table Name: A

Below is Example for SQL built-in Function , together with SQL Statement and the answer.

AVG – Average value of columns
Select AVG(Salary) FROM A
Value = 4675

COUNT – number of rows
Select COUNT(*) FROM A
Value = 4

SELECT COUNT (DISTINCT Salary) FROM CUSTOMERS
Value = 3

MAX – Maximun or Highest number in a column
SELECT MAX(Salary) FROM CUSTOMERS
Value = 5000

MAX – Minimum or Lowest number in a column
SELECT MIN(Salary) FROM CUSTOMERS
Value = 4000

SUM – Total number in a column
SELECT SUM(Salary) FROM CUSTOMERS
Value = 18500

About onlinejt

Blogger

, ,

No comments yet.

Leave a Reply

*