DolphinDB有没有类似SQL中sum(字段)over(partition by 字段 order by 字段) 的功能?

有如下表:scores

attachments-2022-10-7EOZrozF63526530bf353.png

其中gap为等级,1为最高级,4为最低级,score为得分

现有需求:

计算每个id等级和其前一个等级之间的累计得分

在SQL中可以这么写

select id, gap, sum(score)over(partition by id order by gap desc rows between 1 preceding and current row) as total from t

在DOlphinDB中要如何实现类似功能呢?

请先 登录 后评论

2 个回答

wale

partition by对应的有context by,详见 context by — DolphinDB 2.0 文档

请先 登录 后评论
Xiaohua Zhou

select id, gap, msum(score, 2, 1) as total from t context by id csort score desc

请先 登录 后评论
  • 2 关注
  • 0 收藏,782 浏览
  • wangsenxiao 提出于 2022-10-21 13:20

相似问题