在 Neo4j 中如何按一个 return 键分组,而不是 return 中的所有非聚合键?
In Neo4j how to group by one return key, instead of all non aggregate keys in return?
4.3. Aggregating functions To calculate aggregated data, Cypher offers aggregation, analogous to SQL’s GROUP BY.
Aggregating functions take a set of values and calculate an aggregated
value over them. Examples are avg() that calculates the average of
multiple numeric values, or min() that finds the smallest numeric or
string value in a set of values. When we say below that an aggregating
function operates on a set of values, we mean these to be the result
of the application of the inner expression (such as n.age) to all the
records within the same aggregation group.
Aggregation can be computed over all the matching subgraphs, or it can
be further divided by introducing grouping keys. These are
non-aggregate expressions, that are used to group the values going
into the aggregate functions.
Assume we have the following return statement:
RETURN n, count(*)
We have two return expressions: n, and count(). The first, n, is not an aggregate function, and so it will be the grouping key. The
latter, count() is an aggregate expression. The matching subgraphs
will be divided into different buckets, depending on the grouping
key. The aggregate function will then be run on these buckets,
calculating an aggregate value per bucket.
我不知道如何:
RETURN n, m COLLECT(n);
例如,并且只使用n
作为分组键,不能同时使用n
和m
。
这在 Cypher 中是不可能的,因为正如您从文档中了解到的那样,它会隐式分组。它与 SQL 非常相似,只是您必须明确添加 GROUP BY
子句。
您可以使用 subqueries,或将查询分成两部分,首先聚合数据,然后在第二部分再次遍历每个节点。
4.3. Aggregating functions To calculate aggregated data, Cypher offers aggregation, analogous to SQL’s GROUP BY.
Aggregating functions take a set of values and calculate an aggregated value over them. Examples are avg() that calculates the average of multiple numeric values, or min() that finds the smallest numeric or string value in a set of values. When we say below that an aggregating function operates on a set of values, we mean these to be the result of the application of the inner expression (such as n.age) to all the records within the same aggregation group.
Aggregation can be computed over all the matching subgraphs, or it can be further divided by introducing grouping keys. These are non-aggregate expressions, that are used to group the values going into the aggregate functions.
Assume we have the following return statement:
RETURN n, count(*)
We have two return expressions: n, and count(). The first, n, is not an aggregate function, and so it will be the grouping key. The latter, count() is an aggregate expression. The matching subgraphs will be divided into different buckets, depending on the grouping key. The aggregate function will then be run on these buckets, calculating an aggregate value per bucket.
我不知道如何:
RETURN n, m COLLECT(n);
例如,并且只使用n
作为分组键,不能同时使用n
和m
。
这在 Cypher 中是不可能的,因为正如您从文档中了解到的那样,它会隐式分组。它与 SQL 非常相似,只是您必须明确添加 GROUP BY
子句。
您可以使用 subqueries,或将查询分成两部分,首先聚合数据,然后在第二部分再次遍历每个节点。