我有一个运行良好的查询。这给了我所有当前fuelPercentLeft超过50%的列车。
MATCH (t:Train)
WITH t.trainId AS trainid, MAX(t.timestamp) AS maxTimeStamp
MATCH (n:Train{trainId: trainid, timestamp: maxTimeStamp})-[:HAS]->(m:Attributes{name:'fuelPercentLeft'})
WHERE toInteger(m.value) > 50
RETURN count(toInteger(m.value))
我只想用一个查询返回多个结果。例如,对于所有的列车,返回fuelPercentLeft大于50、Engine Temperature小于20、Lubricant Level小于10的所有列车。在上面的查询中,是否可以应用多个WHERE条件?我们是否可以执行以下操作?
MATCH (t:Train)
WITH t.trainId AS trainid, MAX(t.timestamp) AS maxTimeStamp
CALL {
MATCH (n:Train{trainId: trainid, timestamp: maxTimeStamp})-[:HAS]->(m:Attributes{name:'fuelPercentLeft'})
WHERE toInteger(m.value) > 50
RETURN count(toInteger(m.value)) AS goodFuel
}
CALL {
MATCH (n:Train{trainId: trainid, timestamp: maxTimeStamp})-[:HAS]->(m:Attributes{name:'fuelPercentLeft'})
WHERE toInteger(m.value) < 50
RETURN count(toInteger(m.value)) AS badFuel
}
CALL {
MATCH (n:Train{trainId: trainid, timestamp: maxTimeStamp})-[:HAS]->(m:Attributes{name:'engineTemp'})
WHERE toInteger(m.value) > 20
RETURN count(toInteger(m.value)) AS goodEngine
}
CALL {
MATCH (n:Train{trainId: trainid, timestamp: maxTimeStamp})-[:HAS]->(m:Attributes{name:'lubricantLevel'})
WHERE toInteger(m.value) < 10
RETURN count(toInteger(m.value)) AS badLubricant
}
RETURN goodFuel, badFuel, goodEngine, badLubricant
我试过这个,但它不像预期的那样工作。要求是,一个单一的查询应该能够基于多个条件返回多个值。
请帮忙。谢谢!
2条答案
按热度按时间ztyzrc3y1#
您可以在链中使用可选匹配:
5sxhfpxr2#
您应用了错误的筛选器,对于
trainId
和maxTimeStamp
,它们不是必需的,请尝试以下操作: