AGGREGATE FUNCTIONS

: An  aggregate function in SQL performs a calculation on multiple values and returns a single value. Aggregate functions that include avg, count, sum, min, max, etc. An aggregate function ignores NULL values when it performs the calculation, except for the count function.

  • Min and Max – The MIN() function returns the smallest value of the selected column and the MAX() function returns the largest value of the selected column.

SYNTAX:

Select Min(column_name)
From table_name
Where condition;

SYNTAX:

Select Max(column_name)
From table_name
Where condition;

The order_products1 table has been given below

The below syntax returns the minimum item_cost value from the list of item costs which are less than or equal to Rs.3799

The below syntax returns the maximum item_cost value from the list of item costs which are greater  than or equal to Rs.25000

  • Sum– The SUM() function returns the total sum of a numeric column.

SYNTAX:

Select SUM(column_name)
From table_name
Where condition;

The below syntax returns the sum of item_cost values which are less than or equal to Rs.1599

select * from order_products1 where cust_name LIKE ‘%________d’;

Below screen shot will show the order name with alphabet ‘d’ after 8 characters.

  • Count: The count()function returns the number of rows that matches a specified criterion.

SYNTAX:

Select count(column_name)
From table_name
Where condition;

The below syntax returns the count of item cost values which are less than or equal to Rs.1599

 

  • Avg : The AVG()function returns the average value of a numeric column.

SYNTAX:

Select Avg(column_name)
From table_name
Where condition;

The below syntax returns the average  item_cost value which are less than or equal to Rs.2199