SQL集合函数用于对数据进行聚合计算,常用的集合函数包括SUM、COUNT、AVG、MIN和MAX等。下面是一些使用SQL集合函数进行数据处理的示例:
SELECT SUM(salary) AS total_salary
FROM employees;
SELECT COUNT(*) AS total_employees
FROM employees;
SELECT AVG(salary) AS average_salary
FROM employees;
SELECT MIN(salary) AS min_salary
FROM employees;
SELECT MAX(salary) AS max_salary
FROM employees;
除了以上示例,SQL集合函数还可以与GROUP BY子句一起使用,对数据进行分组计算。通过灵活运用SQL集合函数,可以方便地对数据进行统计和分析。