Aggregate Functions

Cards (15)

  • An Aggregate function is a function that groups together the values of multiple rows to return a single statistical value.
  • MIN() returns the smallest value of the selected column or expression.
  • MAX() returns the largest value of the selected column or expression
  • SUM() returns the total of the numeric values in a given column.
  • COUNT() returns the number of rows that match the criteria in the WHERE clause.
  • AVG() returns the average value of a numeric column or expression.
  • SUM( ) and AVG( ) can only be applied to numeric data types.
  • MIN( ) and MAX( ) work with characters, numeric, and date/time datatypes
  • COUNT( ) works with all data types.
  • All aggregate functions except, COUNT( ), ignore nulls
  • COUNT( ) always returns a positive integer or zero. The other aggregate functions return null if the set contains no rows or contains rows with only nulls.
  • An aggregate expression cannot be used in a WHERE clause.
  • The GROUP BY clause is used in a SELECT to form sets (or groups) of records. It does this by gathering together all records that have identical data in the specified column(s).
  • When used with an aggregate function, GROUP BY ensures that one result is returned for each set of grouped records. This makes it possible to mix non-aggregate and aggregate expressions for grouping columns; without GROUP BY, this is not possible.
  • You can rename a table or a column temporarily by giving it another name known as an Alias. An alias only exists for the duration of the query. An alias can be used to give any column in an answer table a
    temporary name. Doing this makes the headings in the answer table more readable. Since it is generated at run-time, an alias only exists for the duration of the query. An alias is listed in the SELECT list by using the AS statement.