News Products reviews Technical support Download software Contact information

  Index   


Interactive SQL Tutorial

9. Miscellaneous SQL statements

Aggregate Functions

I will discuss five important aggregate functions: SUM, AVG, MAX, MIN, and COUNT. They are called aggregate functions because they summarize the results of a query, rather than listing all of the rows.

SUM () gives the total of all the rows, satisfying any conditions, of the given column, where the given column is numeric.

AVG () gives the average of the given column.

MAX () gives the largest figure in the given column.

MIN () gives the smallest figure in the given column.

COUNT(*) gives the number of rows satisfying the conditions.

Looking at the tables at the top of the document, let's look at three examples:

SELECT SUM(SALARY), AVG(SALARY)

FROM EMPLOYEESTATISTICSTABLE

This query shows the total of all salaries in the table, and the average salary of all of the entries in the table.

SELECT MIN(BENEFITS)

FROM EMPLOYEESTATISTICSTABLE

WHERE POSITION = 'Manager'

This query gives the smallest figure of the Benefits column, of the employees who are Managers, which is 12500.

SELECT COUNT(*)

FROM EMPLOYEESTATISTICSTABLE

WHERE POSITION = 'Staff'

This query tells you how many employees have Staff status (3).



<< Prev 1 2 3 4 5 6 7 8 9 10 11 12 13 Next >>



If you like to see how it works enter SQL statement and press Execute





© 1999 � 2002 XLineSoft. All rights reserved. All comments send to webmaster@xlinesoft.com
Designed by XLineSoft