oracle 月销售总金额的累加计算,实现 n = (n-1) + (n-2)
2011-11-30 09:24
651 查看
在Oracle 当中如要实现下面这种情况
2 月分的销售总金额= 1 月分金额 + 2 月分的金额
3 月分的销售总金额= 1 月分金额 + 2 月分的金额 + 3 月分的金额。
...
12 月分的销售总金额= 1 + 2 + ... 12 月分金额。
现在在有一张表如数据如下图所示。
现在用 下面代码实现当前月销售总金额累加的计算
主要是 sum(sum(amount))over(order by month rows between unbounded preceding and current row) 句话,按月销售金额进行相加。
第N值= n -1 的值 + n-2 的值。
如果想求第 6 个份 到10月份的话
2 月分的销售总金额= 1 月分金额 + 2 月分的金额
3 月分的销售总金额= 1 月分金额 + 2 月分的金额 + 3 月分的金额。
...
12 月分的销售总金额= 1 + 2 + ... 12 月分金额。
现在在有一张表如数据如下图所示。
现在用 下面代码实现当前月销售总金额累加的计算
select year, month,sum(amount) as month_sum, sum(sum(amount))over(order by month rows between unbounded preceding and current row)cumulative_amount from all_sales t group by year,month
主要是 sum(sum(amount))over(order by month rows between unbounded preceding and current row) 句话,按月销售金额进行相加。
第N值= n -1 的值 + n-2 的值。
如果想求第 6 个份 到10月份的话
select year, month,sum(amount) as month_sum, sum(sum(amount))over(order by month rows between unbounded preceding and current row)cumulative_amount from all_sales t where t.month between 6 and 10 group by year,month
相关文章推荐
- oracle 月销售总金额的累加计算,实现 n = (n-1) + (n-2)
- oracle实现累加,累计百分比计算
- 在GridView控件内文本框实现TextChanged事件,勾选复选框时 :textbox文本框可编辑,编辑文本框的数字后 总金额会重新计算并统计
- 利用 SUM OVER 开窗函数实现累加计算
- Java实现的贷款金额计算功能示例
- Oracle 累加和实现
- 累加功能的实现 (累计计算)
- Oracle计算时间差为毫秒的实现代码
- DataGrid中实现输入数量和金额自动计算出总金额
- Oracle 数据库中实现三元运算和逻辑计算
- Oracle中实现javascript中的Eval函数计算效果
- shell script 实现累加计算
- oracle用sum函数实现累加
- oracle用sum函数实现累加
- 机房重构利用策略模式+简单工厂实现消费金额的计算
- Oracle中实现javascript中的Eval函数计算效果
- oracle sql语句实现累加、累减、累乘、累除
- Oracle 实现累加(全)
- 【Oracle】实现计算两个日期相差工作小时数的Function