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
.
Under the assumption that your collection with the transactions is named 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"]},
...
]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.