【问题标题】:Calculate percentage in groups in DolphinDB在 DolphinDB 中按组计算百分比
【发布时间】:2021-02-17 19:49:43
【问题描述】:

有没有方便的方法来计算 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


    【解决方案1】:

    在 dolphindb 中使用 SQL 扩展 context by

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-10-08
      • 1970-01-01
      • 2014-12-24
      • 2020-12-03
      • 1970-01-01
      • 1970-01-01
      • 2020-02-18
      • 2022-01-21
      相关资源
      最近更新 更多