【发布时间】:2026-01-08 15:30:01
【问题描述】:
我有一个要求,其中有一个如下所示的表格
Invoice Date Year Amount
1001 04-NOV-15 2015 100
1001 04-NOV-16 2016 400
1001 04-NOV-17 2017 600
1002 01-OCT-17 2014 1000
我希望最后有一列应该计算时尚差异
Invoice Date Year Amount Calculation
1001 04-NOV-15 2015 100 0
1001 04-NOV-16 2016 400 ((04-NOV-16)-(04-NOV-15))/(400-300)
1001 04-NOV-17 2017 600 ((04-NOV-17)-(04-NOV-16))/(600-400)
1002 01-OCT-14 2014 1000 0
1002 01-OCT-18 2018 2000 ((01-OCT-18)-(01-OCT-14))/(2000-1000)
1003 01-JAN-14 2014 1000 0
计算栏是必填项和
我尝试了下面给出金额差异的查询
select invoice,
date_value,
Year_va,
amount,
amount-lag(amount) over (partition by invoice
order by date_value,invoice
) diff
from sample;
当尝试了
select invoice,
date_value,
Year_va,
amount,
MOD(date_value-lag(date_value),amount-lag(amount)) over (partition by invoice
order by date_value,invoice
) diff
from sample;
由于窗口函数错误而失败。
有人可以帮忙吗....
【问题讨论】:
标签: sql oracle plsql oracle11g