在SQL中,聚合函數(shù)用于對一組數(shù)據(jù)進行計算并返回一個單一的值。常見的聚合函數(shù)包括SUM、AVG、COUNT、MIN和MAX等。
以下是一些常見的聚合函數(shù)用法示例:
SELECT SUM(salary) AS total_salary
FROM employees;
SELECT AVG(salary) AS avg_salary
FROM employees;
SELECT COUNT(employee_id) AS num_employees
FROM employees;
SELECT MIN(salary) AS min_salary
FROM employees;
SELECT MAX(salary) AS max_salary
FROM employees;
除了以上示例,聚合函數(shù)還可以進行分組計算、嵌套使用等復(fù)雜操作,可以根據(jù)具體需求靈活運用。