如何找到间隔100天的金额? 我有这个选择:
data_final.to_excel(writer,'Sheet1',float_format='%.8f',index=False)
答案 0 :(得分:0)
您正确地做到了。另一种方法是相关子查询,如下所示。但是窗口函数正是为此目的而设计的,您应该使用它们而不是子查询。它们更快。
select id, date_, amn,
sum(amn) over(partition by id order by date_
range between interval '100' day(3) preceding
and current row) s1,
(select sum(amn)
from ddd d2
where ddd.id = d2.id
and date_ between ddd.date_ - interval '100' day(3)
and ddd.date_) s2
from ddd