Aggregative Function:
Aggregate functions perform calculations on multiple rows and return a single result.
Theyโre essential for:
- Summarizing data (e.g., total salary, average marks)
- Analyzing trends (e.g., highest sales, number of employees per department)
- Filtering grouped results using HAVING
#Common SQL Aggregate Functions:
SELECT SUM(salary) FROM Employee;
SELECT COUNT(*) FROM Employee;
SELECT MAX(salary) FROM Employee;
SELECT MIN(salary) FROM Employee;
Using Aggregate Functions with GROUP BY:
SELECT dept_id, AVG(salary)
FROM Employee
GROUP BY dept_id;
Filtering Groups with HAVING
SELECT dept_id, COUNT(*) AS emp_count
FROM Employee
GROUP BY dept_id
HAVING COUNT(*) > 5;
Shows only departments with more than 5 employees.
Bye.. bye..
Top comments (0)