SQL Aggregate Functions

Following are the Common SQL Aggregate Functions:

COUNT:

Select Count of records from a result set.

SELECT COUNT(*)
FROM TABLE_NAME

SELECT COUNT(Column_Name)
FROM TABLE_NAME
WHERE Column_Name = <condition>

SELECT Column_Name1, COUNT(Column_Name2)
FROM table_name
WHERE column_name = 10
GROUP BY Column_Name1

SUM:

Select arithmetic SUM of a column from a result set.

SELECT SUM(Column_Name)
FROM TABLE_NAME
WHERE Column_Name = <condition>

SELECT Column_Name1, SUM(Column_Name2)
FROM table_name
WHERE column_name = 10
GROUP BY Column_Name1

MIN:

Select Minimum value of a column from a result set.

SELECT MIN(Column_Name)
FROM TABLE_NAME
WHERE Column_Name = <condition>

SELECT Column_Name1, MIN(Column_Name2)
FROM table_name
WHERE column_name = 10
GROUP BY Column_Name1

MAX:

Select Maximum value of a column from a result set.

SELECT MAX(Column_Name)
FROM TABLE_NAME
WHERE Column_Name = <condition>

SELECT Column_Name1, MAX(Column_Name2)
FROM table_name
WHERE column_name = 10
GROUP BY Column_Name1

AVE:

Select average value of a column from a result set.

SELECT AVE(Column_Name)
FROM TABLE_NAME
WHERE Column_Name = <condition>

SELECT Column_Name1, AVE(Column_Name2)
FROM table_name
WHERE column_name = 10
GROUP BY Column_Name1

81 views

Return to top