
March 19, 2025 08:23 by
Peter
Obtaining the sum of a set of numbers, like the total salary, is frequently required when using SQL searching. For this procedure, SQL has developed special functions called Aggregate Functions or Grouping Functions. When working with numerical and statistical data, aggregate functions are employed for grouping, which enables us to get results following a sequence of simple or complex mathematical computations.
Aggregate functions are predefined functions that carry out the required activities and produce the results when set up during a database query in accordance with our requirements.
Aggregate functions, such as Sum and Count, are characterized by their ability to return a single number after performing particular calculations on the data in a column.
Next, we will examine these functions.
Min Function
This function is used to obtain the minimum value from similar values.
SELECT MIN(grade)
FROM StudentGrade;
In the example above, we use this function to find the lowest score of students in the student grades table.
Max Function
This function is exactly the opposite of the Min function; it is used to find the maximum value among similar values.
SELECT MAX(salary)
FROM Personnel
WHERE Age < 35;
In this example, it finds and displays the highest salary among personnel who are under 35 years old.
Sum Function
This function is used to obtain the sum of numbers.
SELECT SUM(Salary)
FROM Personnel;
In this example, this function is used to sum all the salaries of the personnel in the personnel table.
Count Function
As the name of this function indicates, it is used to obtain the number of items.
SELECT COUNT(Id)
FROM Personnel;
The Count function is used to find the number of personnel.
Avg Function
The AVG function is actually an abbreviation for “average.” Using the AVG function, we can calculate and display the average of the desired values from grouped columns.
SELECT AVG(Salary)
FROM Personnel;
In this example, the AVG function is used to calculate the average salary of the personnel.
HostForLIFEASP.NET SQL Server 2022 Hosting
