https://ask.dolphindb.net/question/1070 计算结果不对

代码对于我给的例子是对的,但换了下数字就不对了

timer t = table(1 2 3 4 5 as volume)

timer tmp = select volume, iif(deltas(volume)>0, rowNo(volume), NULL) as flag from t

timer tmp.bfill!()

select volume, cumrank(volume) from tmp context by flag


结果是01000  应该为01234




请先 登录 后评论

1 个回答

Shena Mao

你看一下这样可以满足吗?

t = table(1 2 3 4 5 3 8 4 2 3 9 9 as volume)
tt = select volume, iif(cumrank(volume) = (cumcount(volume)-1), cumrank(volume), 0) as newcount from t
tmp = select volume, newcount , bfill(iif(deltas(volume)>=0, rowNo(volume), NULL)) as flag from tt
aa = select volume, newcount,cumrank(volume) as cumrank from tmp context by flag
aa.update!(`cumrank,<newcount>,<(cumrank = 0)>).dropColumns!(`newcount)
aa
请先 登录 后评论
  • 1 关注
  • 0 收藏,1005 浏览
  • ddbuserex 提出于 2021-12-15 10:53

相似问题