[英]arangodb AQL aggregate result and return object
I want to aggregate some ratings in AQL.我想在 AQL 中汇总一些评级。 The below query下面的查询
FOR l IN locations
COLLECT rating = l.rating WITH COUNT INTO ratings
RETURN {[rating]: ratings}
returns and array of object:返回和数组 object:
[
{
"Good": 4639
},
{
"Bad": 517
},
{
"So so": 1017
}
]
what I need is one object like:我需要的是一个 object,例如:
[
{
"Good": 4639,
"Bad": 517,
"So so": 1017
}
]
You can use MERGE
( doc ) to achieve the desired result:您可以使用MERGE
( doc ) 来获得所需的结果:
RETURN MERGE (
FOR l IN locations
COLLECT rating = l.rating WITH COUNT INTO ratings
RETURN {[rating]: ratings}
)
Tested with my test
collection (using prop2
rather than rating
):使用我的test
集进行测试(使用prop2
而不是rating
):
[
{
"baz": 1,
"other": 2
}
]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.