简体   繁体   English

如何在ArangoDB中计算模式?

[英]How to calculate the mode in ArangoDB?

I have transactions like this 我有这样的交易

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

I want to summarize how many unique customers and for each customer how many unique accounts that customer has and the mode value for account status by frequencies? 我想总结一下有多少个唯一客户,每个客户有多少个唯一帐户,以及按频率显示帐户状态的模式值?

Expected Result: 预期结果:

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

Thank you 谢谢

You can use COLLECT to group the documents by cust_id . 您可以使用COLLECTcust_id对文档进行分组。

Under the assumption that your collection with the transactions is named transactions , 假设您的交易集合称为transactions

this query: 此查询:

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

give you the following result: 给您以下结果:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM