【问题标题】:How to calculate the mode in ArangoDB?如何计算 ArangoDB 中的模式?
【发布时间】:2017-06-13 01:15:36
【问题描述】:

我有这样的交易

{"cust_id": "593ec", "recorded": "2015-10-15T11:22:22", "account_id": 1, "account_status": "P"},
{"cust_id": "593ec", "recorded": "2016-03-06T02:00:11", "account_id": 2, "account_status": "A"}, ...

我想总结有多少唯一客户,每个客户有多少个唯一帐户,以及按频率划分的帐户状态的众数值?

预期结果:

[
   {"cust_id": "593ec", "accounts": 11, "status_q1": "A", "status_q2": "N"},
   {"cust_id": "114sd", "accounts": 0,  "status_q1": "P", "status_q2": "P"},
   .....
]

谢谢

【问题讨论】:

    标签: arangodb aql nosql


    【解决方案1】:

    您可以使用COLLECT将文档按cust_id分组。

    假设您的交易集合命名为transactions

    这个查询:

    FOR t IN transactions
      COLLECT c = t.cust_id INTO status = t.account_status
      RETURN {cust_id: c, accounts : LENGTH(status), status}
    

    给你以下结果:

    [
      {"cust_id": "593ec", "accounts": 2, "status": ["P","A"]},
      ...
    ]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-12-15
      • 1970-01-01
      • 2017-03-06
      • 2012-10-28
      • 2013-08-13
      • 1970-01-01
      • 2011-11-03
      相关资源
      最近更新 更多