我正在尝试了解Cypher中以下查询的输出。
start n=node:node_auto_index(name="root_node")
match n-[:SC]->c, b<-[:CB]-c-[:CB]->b1
where (b.days_in_number - b1.days_in_number <= 7) AND (b.days_in_number > b1.days_in_number)
and c.name = "C16659"
with distinct n,c, b, b1
match n-[:SC]->c-[:CB]->b-[:CT]->i1, n-[:SC]->c-[:CB]->b1-[:CT]->i2
with b.name as bname,b1.name as b1name,i1.name as i1name,i2.name as i2name
return bname,b1name,i1name,i2name
order by bname,b1name,i1name,i2name;
返回3680行
start n=node:node_auto_index(name="root_node")
match n-[:SC]->c, b<-[:CB]-c-[:CB]->b1
where (b.days_in_number - b1.days_in_number <= 7) AND (b.days_in_number > b1.days_in_number)
and c.name = "C16659"
with distinct n,c, b, b1
match b-[:CT]->i1, b1-[:CT]->i2
with b.name as bname,b1.name as b1name,i1.name as i1name,i2.name as i2name
return bname,b1name,i1name,i2name
order by bname,b1name,i1name,i2name;
返回184行
查询1似乎在做笛卡儿,但我无法理解为什么?有人可以解释一下吗?
c - [:CB] - &gt; b是1:n关系。
更新:
当我运行以下查询时,我得到了正确的184个结果:
start n=node:node_auto_index(name="root_node")
match n-[:SC]->c, b<-[:CB]-c-[:CB]->b1
where (b.days_in_number - b1.days_in_number <= 7) AND (b.days_in_number > b1.days_in_number)
and c.name = "C16659"
with distinct n,c, b, b1
match c-[:CB]->b-[:CT]->i1, c-[:CB]->b1-[:CT]->i2
with n.name as nname,c.name as cname, b.name as bname,b1.name as b1name,i1.name as i1name,i2.name as i2name
return nname,cname,bname,b1name,i1name,i2name
order by nname,cname,bname,b1name,i1name,i2name;
这表明将n个引线引向笛卡儿。
n - [:SC] - &gt; c是1:1的关系。为什么会这样?
答案 0 :(得分:0)
您是否确认n和c之间的关系真的很独特?也许看着路径会有所帮助。尝试
match p1=n-[:SC]->c-[:CB]->b-[:CT]->i1, p2=n-[:SC]->c-[:CB]->b1-[:CT]->i2
return p1,p2
查看其他结果之间的差异。