如何查询Node属性?

时间:2018-02-08 00:15:40

标签: neo4j cypher

create (s:Student {name:'Jack'}), 
(t:Teacher {name: 'Mary', age: '30'}), 
(s)-[r:has_teacher]->(t)

如何制作此Cypher查询问题:

找到杰克老师的名字,答案应该是'玛丽'。

2 个答案:

答案 0 :(得分:1)

考虑到评论中的要求,您可以忽略教师姓名为null的模式:

MATCH (s:Student)-[r:has_teacher]->(t:Teacher)
where s.name = "Jack" and t.name is not null
return t.name;

在某些情况下,您可能只想查询:Teacher个节点具有name属性的模式:

MATCH (s:Student)-[r:has_teacher]->(t:Teacher)
where s.name = "Jack" and EXISTS(t.name)
return t.name;

答案 1 :(得分:0)

试试这个:

MATCH (s:Student)-[r:has_teacher]->(t:Teacher) where s.name = "Jack" return t.name;
相关问题