neo4j-计算结果中的重复数量

发布于 2025-02-08 07:25:24 字数 1999 浏览 2 评论 0原文

社区,

我是Neo4J的新手,我正在尝试获取一个节点列表(没有特定关系)并计算节点名称重复。

查询:

MATCH (e:ExampleNode)
WHERE NOT exists((e)-[:EXAMPLE_REL]->())
RETURN e.name as name, count(e.name) as count

结果:

名称计数
名称1 3
name231
name84

到目前为止很好...

在节点的名称外,我还需要更多值。此值使每个结果唯一,并分别返回每个节点(如果名称相同)。

查询:

MATCH (e:ExampleNode)
WHERE NOT exists((e)-[:EXAMPLE_REL]->())
RETURN e.name as name, count(e.name) as count, e.property as someValue

结果:

名称计数somevalue
name11abc
name11cba
name11xyz
name231abc
name81123
name8 name81321
name81987
name8 name81789
.........

...喜欢:

名称计数somevalue
name13abc
name13cba
name13xyz
name231abc
name84123
name8 name84321
name84987
name8 name84789
.........

我想返回每个hasn'的节点' t特定的关系并按名称计数所有重复。

那么,是否有可能获得我想要的结果?

Community,

I am new to neo4j and I'm trying to get a list of nodes (that has not a specific relation) and count node name duplicates.

Query:

MATCH (e:ExampleNode)
WHERE NOT exists((e)-[:EXAMPLE_REL]->())
RETURN e.name as name, count(e.name) as count

Result:

namecount
name13
name231
name84

So far so good...

Beside the name of the node I also need some more values. This value makes each result unique and returns every node separately even (if the name is the same).

Query:

MATCH (e:ExampleNode)
WHERE NOT exists((e)-[:EXAMPLE_REL]->())
RETURN e.name as name, count(e.name) as count, e.property as someValue

Result:

namecountsomeValue
name11abc
name11cba
name11xyz
name231abc
name81123
name81321
name81987
name81789
.........

But...this is the result I would like to have:

namecountsomeValue
name13abc
name13cba
name13xyz
name231abc
name84123
name84321
name84987
name84789
.........

I would like to return every node that hasn't the specific relation and count all duplicates by the name.

So, is it possible to get the result I would like to have?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

酒解孤独 2025-02-15 07:25:24

是的。计算计数时,请使用收集函数在列表中收集属性值,然后在上一个列表上使用Undind,以获取每个属性的不同行。像这样:

MATCH (e:ExampleNode) 
WHERE NOT exists((e)-[:EXAMPLE_REL]->()) 
WITH e.name as name, count(e.name) as count, collect(e.property) as properties 
UNWIND properties as property 
RETURN name, count, property

Yess it is possible. When calculating the count, collect the property values in a list using collect function and then use UNWIND on the previous list, to get distinct rows for each property. Like this:

MATCH (e:ExampleNode) 
WHERE NOT exists((e)-[:EXAMPLE_REL]->()) 
WITH e.name as name, count(e.name) as count, collect(e.property) as properties 
UNWIND properties as property 
RETURN name, count, property
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文