Experiment 08
Aim
To demonstrate the use of aggregate functions i.e., min, max, count, sum, and average
Theory
Aggregate functions perform a calculation on a set of values and return a single value. They are often used with the GROUP BY clause in SQL to group the result set by one or more columns.
-
Min and Max:
The
MIN()function returns the smallest value in a set, while theMAX()function returns the largest value.SyntaxSELECT MIN(column_name) FROM table_name;
SELECT MAX(column_name) FROM table_name; -
Count, Sum, and Average:
The
COUNT()function returns the number of rows that match a specified condition, theSUM()function returns the total sum of a numeric column, and theAVG()function returns the average value of a numeric column.SyntaxSELECT COUNT(column_name) FROM table_name;
SELECT SUM(column_name) FROM table_name;
SELECT AVG(column_name) FROM table_name;
Commands
SELECT MIN(salary) AS MinimumSalary FROM Employees;
SELECT MAX(salary) AS MaximumSalary FROM Employees;
SELECT COUNT(*) AS TotalEmployees FROM Employees;
SELECT SUM(salary) AS TotalSalary FROM Employees;
SELECT AVG(salary) AS AverageSalary FROM Employees;
Conclusion
Successfully demonstrated the use of various aggregate functions in SQL, including
MIN(),MAX(),COUNT(),SUM(), andAVG()