Web Development & Technology Resources

What is SQL Aggregate function

Let’s learn about SQL aggregate function in this article. Requirement for Aggregrate function is that a data should be grouped  into some sort of group. This function produces records to retrieve one value for whole group and if record is grouped by group clause than only one value will be returned for each group. Also if group by clause is not used than whole table groups into one value as a result of aggregrate function.

Aggregrate functions are listed below:

  1. Count() : it return total number of record in a table
  2. SUM() : it return the total sum in a column
  3. MIN() : it return the minimum value in a column
  4. MAX() :it return the maximum value in a column
  5. AVG() : it return the average of value in a column

Now let’s see the usage of above aggregate functions in detail:

  1. It return’s the total sum in a column
  2. It return’s the sum of numeric column
  3. Consider following salary table:
  4. In the above example we are having totally disturbed salary for each department
    Sql query: select sum(monthlysalary)as totalsalary, department from salary group by department order by totalsalary
    Output: Above query resulted into total salary by each department group.
  • MAX():
    1. It returns the maximum/largest value in a column
    2. Consider following salary table:
  • MIN():
    1. It will return the minimum value in a column
    2. Consider the following salary table:
  • AVG():
    1. It return’s the average value in a column
    2. Consider the following salary table:

    Thus, we learnt SQL aggregate functions in detail with examples.

    Exit mobile version