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集合函數,可以方便地對數據進行統計和分析。