The SUM function calculates the sum of a series of values in Oracle. Syntax: SUM(expression), where expression is a numeric expression or column name. It can sum all row values in a column, or sum rows that meet a specific condition via a WHERE clause. The SUM function returns a value of type NUMBER and returns a positive number even if the argument is negative. It supports advanced usage, such as with GROUP BY and HAVING clauses, and as a window function.
The SUM function in Oracle
Definition
The SUM function is in Used in Oracle to calculate the sum of a set of values or expressions.
Syntax
<code>SUM(expression)</code>
Where:
Usage
Example
<code>-- 计算所有员工的薪水总和 SELECT SUM(salary) FROM employees; -- 计算部门 ID 为 10 的所有员工的薪水总和 SELECT SUM(salary) FROM employees WHERE department_id = 10; -- 计算大于 5000 美元的薪水总和 SELECT SUM(salary) FROM employees WHERE salary > 5000;</code>
Note
Advanced Usage
In addition to basic usage, the SUM function also supports some advanced usage:
The above is the detailed content of How to use sum function in oracle. For more information, please follow other related articles on the PHP Chinese website!