问答交流

row子句结果有问题

由luvymhq创建,最终由luvymhq 被浏览 11 用户

import dai
dai.query(""" select instrument,date,daily_return,close,
            cumsum(close) over(partition by instrument order by date rows between 10 preceding and current row) as nn
            ,cumsum(close) over(partition by instrument order by date rows between 10 preceding and 5 preceding) as mmm
            from cn_stock_prefactors
            where date between '2024-01-01' and '2024-09-10'
              and instrument='000002.SZ'""").df()

nn 和mm 的结果完全一样。但我求和的函数不一样。哪里出了问题?

评论
  • cumsum()是计算累加值,他不适用于 窗口函数,你可以尝试下 sum()
{link}