Oracle sum over
时间: 2023-12-31 10:06:49 浏览: 35
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()`.
相关推荐
![application/msword](https://img-home.csdnimg.cn/images/20210720083327.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)