【问题标题】:And condition in neo4j cypher query doesn't workNeo4j 密码查询中的条件不起作用
【发布时间】:2017-12-23 07:01:29
【问题描述】:

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

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

这给了我所有停靠在车站 id='101' 或 '65' 的火车。 但是当我运行下面的密码来获取所有停靠在 id='101' 和 '65' 的火车时,我什么也没得到

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

这是一个简单的密码,但我找不到查询的问题。谁能帮我找出问题所在?

【问题讨论】:

  • 这个查询工作正常。匹配 (train:Train)-[:STOP_AT]->(:Station{id:'65'}) where (train)-[:STOP_AT]->(:Station{id:'101'}) 返回火车;我不知道为什么第一个密码对我不起作用
  • 这个逻辑行不通,没有一个节点的属性同时是两个不同的值。您可能想查看performing match intersection 上的这篇知识库文章,它可以让您在给定 ID 列表的情况下对任意数量的电台执行您想要的匹配。
  • @InverseFalcon 感谢您的解决方案。这是有道理的

标签: neo4j cypher


【解决方案1】:

在这个查询中:

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;

【讨论】:

    猜你喜欢
    • 2016-12-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-29
    • 1970-01-01
    • 1970-01-01
    • 2018-09-04
    • 1970-01-01
    相关资源
    最近更新 更多