我对Cypher有点陌生,如果我错过了逻辑解决方案,很抱歉。(谢谢你的帮助:)
我所使用的图表用它们的出版日期制作了一个研究出版物网络,并创建了与出版物中提到的分子之间的关系。我试图了解每年增加的新分子的数量。
我试过:
MATCH (p:Publication)-->(m:Molecule)
RETURN DISTINCT datetime(p.releasedDate).year AS release, count(m) ORDER BY release 这将返回一个列表,列出每年不同分子的数量,但仍然有可能(而且很可能)第一年的分子也在第二年,因为按顺序排列似乎是在不同的年份之前。
是否有一种方法首先列出所有不同的分子,然后按年排序?
再次感谢你的帮助。如果需要更多的信息,请告诉我。
发布于 2021-10-25 14:14:11
我试图编写几个查询来说明一些选项:
// Number of molecule mentions per publication year
MATCH (p:Publication)-->(:Molecule)
WITH datetime(p.releasedDate).year AS release, count(*)
// Number of unique molecules mentioned per publication year
MATCH (p:Publication)-->(m:Molecule)
WITH datetime(p.releasedDate).year AS release, count(distinct m)
// Refactor so we know the year a molecule first mentioned
MATCH (p:Publication)-->(m:Molecule)
WITH m, min(datetime(p.releasedDate).year) as yearIntroduced
// Number of new molecules this year, and how many times where they mentioned
MATCH (p:Publication)-->(m:Molecule{yearIntroduced:2021})
RETURN m.name, count(*) as numberOfTimesMentioned
// Same but without refactoring
MATCH (p:Publication)-->(m:Molecule)
WITH m, min(datetime(p.releasedDate).year) as yearIntroduced
WHERE yearIntroduced=2021
MATCH (p:Publication)-->(m)
RETURN m.name, count(*) as numberOfTimesMentioned我希望这能帮上忙!
Cypher手册中的聚合函数:https://neo4j.com/docs/cypher-manual/current/functions/aggregating/
https://stackoverflow.com/questions/69708956
复制相似问题