[英]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.