Sunday, June 3, 2007

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

NameSalary
Emil5000
Chang5000
Emily4500
Nick4000

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