如何计算ArangoDB中的模式?

时间:2017-06-13 01:15:36

标签: arangodb aql nosql

我有这样的交易

{"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"},
   .....
]

谢谢

1 个答案:

答案 0 :(得分:1)

您可以使用COLLECTcust_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"]},
  ...
]