[英]How to calculate the mode in ArangoDB?
我有这样的交易
{"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"},
.....
]
谢谢
您可以使用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"]},
...
]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.