Cypher查询只返回数据

时间:2013-07-08 22:15:53

标签: neo4j cypher

鉴于此图:

http://console.neo4j.org/r/g3j3xo

我试图让所有在同一个schoolType类中影响哲学家的哲学家回归。首先,我将显示正常运行的查询。问题查询位于帖子的底部。

这是上面链接中的默认查询。我打算证明数据存在。也就是说,亚里士多德和柏拉图都分享了SchoolTypeClass'运动'

MATCH p1:Philosopher-[:MEMBER_OF]->s1:School-[:TYPE_OF]->st1:SchoolType-[:SUBCLASS_OF]->stc1:SchoolTypeClass
   WHERE  stc1.name = 'movement'
   RETURN p1.name as p1Name, s1.name as s1Name, st1.name as st1Name, stc1.name as stc1Name

这是一个正常的查询。它与不起作用的查询非常相似。它显示了影响哲学家的哲学家,而不是schoolTypeClass

MATCH st2:SchoolType<-[:TYPE_OF]-s2:School<-[:MEMBER_OF]-p2:Philosopher<-[:INFLUENCES]-p1:Philosopher-[:MEMBER_OF]->s1:School-[:TYPE_OF]->st1:SchoolType
   WHERE  st2 = st1
   RETURN p1.name as p1Name, s1.name as s1Name, st1.name as st1Name, p2.name as p2Name, s2.name as s2Name, st2.name as st2Name

问题查询不返回任何内容。如何让哲学家在同一个schoolType类中影响哲学家?

MATCH stc2:SchoolTypeClass<-[:SUBCLASS_OF]-st2:SchoolType<-[:TYPE_OF]-s2:School<-[:MEMBER_OF]-p2:Philosopher<-[:INFLUENCES]-p1:Philosopher-[:MEMBER_OF]->s1:School-[:TYPE_OF]->st1:SchoolType-[:SUBCLASS_OF]->stc1:SchoolTypeClass
   WHERE stc1 = stc2
   RETURN p1.name as p1Name, s1.name as s1Name, st1.name as st1Name, stc1.name as stc1Name, p2.name as p2Name, s2.name as s2Name, st2.name as st2Name, stc2.name as stc2Name

1 个答案:

答案 0 :(得分:0)

在同一个MATCH(stc1 / 2)中,不能使用不同的名称两次使用相同的节点。

MATCH p=s2:School<-[:MEMBER_OF]-p2:Philosopher
        <-[:INFLUENCES]-p1:Philosopher-[:MEMBER_OF]->s1:School
        -[:TYPE_OF]->st1:SchoolType-[:SUBCLASS_OF]->stc:SchoolTypeClass 
WHERE (stc)<-[:SUBCLASS_OF]-(:SchoolType)<-[:TYPE_OF]-s2 
RETURN p1.name AS p1Name, s1.name AS s1Name, st1.name AS st1Name, 
       stc.name AS stcName, p2.name AS p2Name, s2.name AS s2Name, p

所以你宁愿在赛后检查。

http://console.neo4j.org/r/t6lj05