新 column.Oracle 中不同年份结果的聚合
Аggregation of the result in different years in a new column.Oracle
Тhis is the result i achieved on a monthly basis.
这里我按月收集所有的结果在Comulative。
Е每个新时期都以累积
的形式添加到旧时期
SELECT date,period,SUM(period) OVER(ORDER BY date ) AS Comulative)
按日期分组
date, period cumulative
1-May-19, 1, 1
1-Jun-19, 2, 3
1-Jul-19, 4, 7
1-Aug-19, 1, 8
1-Sep-19, 0, 8
1-May-20, 10, 18
1-Feb-20, 0, 18
1-Mar-20, 0, 18
1-Apr-21, 1, 19
1-Jul-21, 1, 20
1-Aug-21, 1, 21
1-Sep-21, 1, 22
我想每年都达到同样的结果。
date, period, cumolative
2019, 8, 8
2020, 10, 18
2021, 4, 22
我用它来格式化日期。
to_char(日期,'yyyy')
可以先生成SUM结果再做累加和-
SELECT date, period, SUM(period) OVER(ORDER BY date)
FROM (SELECT EXTRACT(YEAR FROM date) date, SUM(period) period
FROM YOUR_TABLE
GROUP BY EXTRACT(YEAR FROM date));
Тhis is the result i achieved on a monthly basis.
这里我按月收集所有的结果在Comulative。 Е每个新时期都以累积
的形式添加到旧时期SELECT date,period,SUM(period) OVER(ORDER BY date ) AS Comulative) 按日期分组
date, period cumulative
1-May-19, 1, 1
1-Jun-19, 2, 3
1-Jul-19, 4, 7
1-Aug-19, 1, 8
1-Sep-19, 0, 8
1-May-20, 10, 18
1-Feb-20, 0, 18
1-Mar-20, 0, 18
1-Apr-21, 1, 19
1-Jul-21, 1, 20
1-Aug-21, 1, 21
1-Sep-21, 1, 22
我想每年都达到同样的结果。
date, period, cumolative
2019, 8, 8
2020, 10, 18
2021, 4, 22
我用它来格式化日期。 to_char(日期,'yyyy')
可以先生成SUM结果再做累加和-
SELECT date, period, SUM(period) OVER(ORDER BY date)
FROM (SELECT EXTRACT(YEAR FROM date) date, SUM(period) period
FROM YOUR_TABLE
GROUP BY EXTRACT(YEAR FROM date));