SQL Aggregate Functions – SQL Tutorial | Software Testing Material
SQL Aggregate Functions:
In this post, we see SQL Aggregate functions in detail.
SQL aggregate functions return a single value, calculated from values in a column.
AVG() – This functions returns the average value
COUNT() – This functions returns the number of rows
MAX() – This functions returns the largest value
MIN() – This functions returns the smallest value
ROUND() – This functions rounds a numeric field to the number of decimals specified
SUM() – This functions returns the sum
Let’s see one by one in detail.
SQL AVG() Syntax:
SELECT AVG(column_name) FROM table_name
Example:
Here I have written two statements to show you the output of complete table and output of average runs.
Copy both the statements as mentioned in the below screenshot and execute it to see the results.
SQL COUNT() Function:
SELECT COUNT(column_name) FROM table_name;
Example:
SQL MAX() Function:
SELECT MAX(column_name) FROM table_name;
SQL MIN() Function:
Â
SELECT MIN(column_name) FROM table_name;
Example:
SQL ROUND() Function:
Â
SELECT ROUND(column_name,decimals) FROM table_name;
Example: If the value is 250.55 and you want to show just 250 then you could pass decimals parameter as 0. Same way if you want to show 250.5 then you could pass decimals value as 1.
SQL SUM() Function:
Â
SELECT SUM(column_name) FROM table_name;
Example:
In the next tutorial, we will learn STRING FUNCTIONS in SQL
Check out the complete SQL Tutorial by clicking on below link: