首页 > 解决方案 > 在 DolphinDB 中计算分组百分比

问题描述

有没有一种方便的方法来计算 DolphinDB 中组中每个项目的百分比?

例如:

groupID x  percentage
1       1  0.25
1       1  0.25
1       2  0.5
2       4  0.2
2       6  0.3
2       10 0.5

在 kdb 中,我可以用fby. 我想知道在 DolphinDB 中是否有类似的方法。

标签: dolphindb

解决方案


context by在 dolphindb 中使用 SQL 扩展:

select groupID, x, x\sum(x) as percentage from t context by groupID

推荐阅读