what aggregate function in sql code example

Example 1: sql aggregate functions

The following are the most commonly used SQL aggregate functions:
AVG – calculates the average of a set of values.
COUNT – counts rows in a specified table or view.
MIN – gets the minimum value in a set of values.
MAX – gets the maximum value in a set of values.
SUM – calculates the sum of values.

The following illustrates the syntax of an aggregate function:
aggregate_function_name(DISTINCT | ALL expression)

In this syntax;

First, specify the name of an aggregate function that you want to use such as AVG, SUM, and MAX.
Second, use DISTINCT if you want only distinct values are considered in the calculation or ALL if all values are considered in the calculation. By default, ALL is used if you don’t specify any modifier.
Third, the expression can be a column of a table or an expression that consists of multiple columns with arithmetic operators.

Example 2: how to use aggregate functions in sql

This is the example.Aggregate function is AVG.production.products is the table.

SELECT
    AVG(list_price) avg_product_price
FROM
    production.products;

Tags:

Sql Example