neo4j添加返回改变匹配的节点数量

发布于 2025-01-14 03:51:59 字数 835 浏览 0 评论 0原文

我正在尝试进行搜索以获得一些基本数据。

MATCH(l:letter)-[:RECIPIENT]-(a:address{country: "England"})
RETURN a

结果 = 56

注意

处理信件时,如果数据库中尚不存在该地址,则添加该地址;如果已存在,则添加关系已创建到现有节点。 因此,这里不应该存在不连接到 letter 节点的地址,尽管 relationship 可能是 sender 而不是 recipient< /代码>。

如果我添加字母计数,我会得到不同的地址计数。

MATCH(l:letter)-[:RECIPIENT]-(a:address{country: "England"})
RETURN a, l

结果 - a = 2, l = 298

同样,如果我只返回字母,我会再次得到不同的数字。

MATCH(l:letter)-[:RECIPIENT]-(a:address{country: "England"})
RETURN l

结果 - l = 300

我错过了什么?

我以为MATCH定义了查询,而RETURN只是选择显示哪些部分的信息,RETURN如何改变匹配的数据?

I am trying to perform a search to get some basic figures.

MATCH(l:letter)-[:RECIPIENT]-(a:address{country: "England"})
RETURN a

Result = 56

Note

When a letter is processed, the address is added if it is not already on the database, if it already exists, a relationship is created to the existing node.
Therefore, no address should exist here that does not connect to a letter node, although the relationship could be sender rather than recipient.

If I add a count for letters, I get a different address count.

MATCH(l:letter)-[:RECIPIENT]-(a:address{country: "England"})
RETURN a, l

Result - a = 2, l = 298

Likewise, if I return only letters, I get different figure again.

MATCH(l:letter)-[:RECIPIENT]-(a:address{country: "England"})
RETURN l

Result - l = 300

What am I missing?

I thought that the MATCH defines the query, and the RETURN is just choosing which parts of the information to display, how does RETURN alter the matched data?

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

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

发布评论

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

评论(1

送舟行 2025-01-21 03:51:59

要获取字母节点的总数,您需要添加 DISTINCT。

MATCH(l:letter)-[:RECIPIENT]-(a:address{country: "England"})
RETURN count(distinct l) as numLetterNodes
MATCH(l:letter)-[:RECIPIENT]-(a:address{country: "England"})
RETURN count(distinct a) as numAddressNodes

当您开始组合结果中的字母和地址时,您最终将得到每行的聚合结果。

MATCH(l:letter)-[:RECIPIENT]-(a:address{country: "England"})
RETURN DISTINCT a.id, count(l) as lettersPerAddress
MATCH(l:letter)-[:RECIPIENT]-(a:address{country: "England"})
RETURN DISTINCT l.id, count(a) as addressesPerLetter

To get the total number of nodes that are letters, you need to add DISTINCT.

MATCH(l:letter)-[:RECIPIENT]-(a:address{country: "England"})
RETURN count(distinct l) as numLetterNodes
MATCH(l:letter)-[:RECIPIENT]-(a:address{country: "England"})
RETURN count(distinct a) as numAddressNodes

When you start combining the letters and addresses in your results you will end up with aggregates per row.

MATCH(l:letter)-[:RECIPIENT]-(a:address{country: "England"})
RETURN DISTINCT a.id, count(l) as lettersPerAddress
MATCH(l:letter)-[:RECIPIENT]-(a:address{country: "England"})
RETURN DISTINCT l.id, count(a) as addressesPerLetter
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文