并且neo4j cypher查询中的条件不起作用

问题描述 投票:1回答:1

我创建了一个带火车和车站的neo4j数据库。每列火车都停在(这是关系)一个车站。我在下面写了cypher查询并得到了附加的响应

match  (train:Train)-[:STOP_AT]->(station:Station)
where station.id='101' or station.id='65'
return train,station;

enter image description here这给了我所有停在车站id ='101'或'65'的列车。但是当我运行下面的密码以获得所有停在id ='101'和'65'的列车时,我什么也没得到

match  (train:Train)-[:STOP_AT]->(station:Station)
where station.id='101' and station.id='65'
return train,station;

这是一个简单的密码,但我找不到查询的问题。有人可以帮我找出问题吗?

neo4j cypher
1个回答
2
投票

在此查询中:

match  (train:Train)-[:STOP_AT]->(station:Station)
where station.id='101' and station.id='65'
return train,station;

你正在寻找一个同时具有id 10165的电台。所以这是不可能的,结果是emtpy。

你想要的是找到一个停在两个车站的火车。所以这是查询:

MATCH  
  (train:Train)-[:STOP_AT]->(station1:Station),
  (train)-[:STOP_AT]->(station2:Station)
WHERE 
  station1.id='101' AND
  station2.id='65'
RETURN train,station;
© www.soinside.com 2019 - 2024. All rights reserved.