Oracle sum over
时间: 2023-12-31 19:06:49 浏览: 126
Oracle 总结
Oracle's `SUM()` function can be used with the `OVER()` clause to calculate a sum of a column's values for each row in a result set. The syntax for using `SUM()` with `OVER()` is as follows:
```
SELECT column1, column2, SUM(column3) OVER (PARTITION BY column4) as sum_column3
FROM table_name;
```
In this example, `column1` and `column2` are the columns you want to select from the table, `column3` is the column you want to sum, and `column4` is the column you want to partition by. The `PARTITION BY` clause divides the result set into partitions based on the values in `column4`. The `SUM()` function calculates the sum of `column3` for each partition created by `column4`. The result set includes all columns selected (`column1`, `column2`, and `sum_column3`).
Note that the `OVER()` clause can also be used with other aggregate functions such as `AVG()`, `MIN()`, and `MAX()`.
阅读全文