Tell Me
 

Group Functions

Previous previous|next Next Page

Sheila has learned that there are several group functions that are available for use. All are ANSI-standard SQL functions.

  • You can find the average of a group of values by using the AVG function.
  • You can find the total of a group of values by using the SUM function.
  • MAX finds a largest value. MIN returns a smallest value.
  • STDDEV returns a standard deviation. VARIANCE returns the statistical variance.
  • AVG , SUM , STDDEV , and VARIANCE can be used with numerical data only. You can use MAX and MIN on character, numeric, and date data types.
  • You can use the COUNT function to return the number of values in a column.

Sheila will use the SQL GROUP functions in her SELECT statements to:

  • Find the number of rows in a table
  • Add the salaries
  • Find the average, maximum, and minimum salaries
  • Analyze salary information by department

To specify a group function, you write the name of the function followed by an argument in parentheses. The argument can be a column name, an expression, or a constant.

The COUNT function returns the number of non-null values in a column. If you count the values of a primary key column or specify COUNT(*), you will find the number of rows in a table because a primary key column cannot contain nulls.