πŸ“˜ SQL Blog Series – 5

 Today, we’re going to understand how to use aggregrate fucntions in Sql.

An aggregate function is a function that performs a calculation on a set of values, and returns a single value.

Aggregate functions are often used with the GROUP BY clause of the SELECT statement. The GROUP BY clause splits the result-set into groups of values and the aggregate function can be used to return a single value for each group.

The most commonly used SQL aggregate functions are:

  • MIN() - returns the smallest value within the selected column
  • MAX() - returns the largest value within the selected column
  • COUNT() - returns the number of rows in a set
  • SUM() - returns the total sum of a numerical column
  • AVG() - returns the average value of a numerical column

Aggregate functions ignore null values (except for COUNT(*)).

We will go through the aggregate functions above in the next chapters.


The SQL MIN() and MAX() Functions

The MIN() function returns the smallest value of the selected column.

Example: This is like our python min method which is used the fetch the small value from a set of values.

The MAX() function returns the largest value of the selected column.

Example: This is like our python max method which is used the fetch the largest from a set of values.

The output of both these are always single it fecthes minimum values or maximum value from a set of valeus.

The SQL COUNT() Function

The COUNT() function returns the number of rows that matches a specified criterion.

Example: The count is method is like the len function in our python .


The SQL SUM() Function

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


The SQL AVG() Function

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


In the next Blog we are going to be see how they are used to filter the data from the database tables.The SQL Aggregate Functions plays a crucial role for both modifying the data or filtering the data in sql.So these are some of the essential fucntions to know about how to peform some operations on data.


Comments

Popular posts from this blog

Welcome to Python Fun Zone: Learn, Code, Build!

Day 1: Getting Started with Python – A Friendly Introduction for Beginners

Day 2: Variables and Data Types – The Building Blocks of Python 🐍