简体   繁体   English

Neo4J-密码查询匹配差异

[英]Neo4J - cypher query match differences

Hi guys I am trying to write a cypher query that will include 2 lists and I will then take the difference of them. 嗨,大家好,我正在尝试编写一个密码查询,其中将包括2个列表,然后我将它们区别对待。

At the end of the day I need to actually run a MATCH query to get both lists and I can't figure out how to construct this to work. 最终,我实际上需要运行一个MATCH查询来获取两个列表,但我不知道如何构造它才能工作。

So the two queries I need to run to generate the list are: 因此,我需要运行以生成列表的两个查询是:

MATCH (Paper:Paper)<-[:WROTE]-(a:Author)
WHERE Paper.year > 2010 and Paper.year <2012
RETURN a

the 2nd one is the same query just a movement of the years from 2010 to 2011 and 2012 to 2013. 第二个是相同的查询,只是从2010年到2011年以及2012年到2013年的变化。

MATCH (Paper:Paper)<-[:WROTE]-(a:Author)
WHERE Paper.year > 2010 and Paper.year <2012
WITH a AS l1, 

(Paper:Paper)<-[:WROTE]-(a:Author)
WHERE Paper.year > 2011 and Paper.year <2013
WITH a AS l2

RETURN [Author in l2 WHERE not(Author in l1)] 

For some reason I get a skew of errors (not surprising) the one being Expression in WITH must be aliased (use AS) (line 5, column 1 (offset: 102)) "(Paper:Paper)<-[:WROTE]-(a:Author)" 由于某种原因,我遇到了一些错误(不足为奇),必须将WITH中的Expression用作别名(使用AS)(第5行,第1列(偏移量:102))“((Paper:Paper)<-[:WROTE] - (一:作者)”

any help would be appreciated! 任何帮助,将不胜感激!

The reason for the error is you have an extra comma at the end of your first WITH clause. 该错误的原因是,在第一个WITH子句的末尾有一个逗号。

That said, it would be wiser to collect the results rather than keep all result rows between your queries, since your current queries aren't working with your results as lists. 就是说,收集结果而不是保留查询之间的所有结果行是比较明智​​的,因为当前的查询无法将结果作为列表使用。

Some other improvements we can make include using chained inequalities: 我们可以做的其他一些改进包括使用链式不等式:

MATCH (Paper:Paper)<-[:WROTE]-(a:Author)
WHERE 2010 < Paper.year < 2012
WITH collect(a) AS l1

MATCH (Paper:Paper)<-[:WROTE]-(a:Author)
WHERE 2011 < Paper.year < 2013
WITH l1, collect(a) AS l2

RETURN [Author in l2 WHERE not Author in l1] as authors

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM