繁体   English   中英

使用Neo4j的Cypher:订购商品处于收集状态且没有空对象

[英]Cypher with Neo4j: Order items in collect and not have empty objects

我正在尝试编写一个密码查询,其中记录了一个人的多维数据集的所有时间。 该查询工作正常,但是我看到的是,如果结果(Time)-[:: RECORDED_ON]-(Cube)中没有任何关系,那么我将在collect中获得1条记录,两个值均为null。 另外,我想在时间集合DESC中订购日期

这是我的密码:

MATCH(a:App{name:'AllAboutCubes'})<-[:MEMBER_OF]-(p:Cuber) WHERE id(p) = 1234
MATCH(p)<-[:BELONGS_TO {is_active:1}]-(c:Cube)
OPTIONAL MATCH (c)-[:TYPE]->(ct:CubeType)
OPTIONAL MATCH (c)<-[:RECORDED_ON]-(t:Time)-[:RECORDED]-(p) 
WITH c,ct,COLLECT({time:t.time,date:t.date}) as times
RETURN c.name as name, c.manufacturer as manufacturer, ct.type as type, id(c) as cube_id, times as times
ORDER BY manufacturer ASC

但我回来了:

"name"  "manufacturer"  "type"  "cube_id"   "times"
"Weipo" "MoYu"  "2x2"   7452    [{"time":null,"date":null}]
"GTS3M" "MoYu"  "3x3"   7453    [{"time":null,"date":null}]
"MoYu Skewb"    "MoYu"  "Skewb" 7458    [{"time":"12.435","date":1553880809832}]
"WuQue" "QiYi MoFangGe" "4x4"   7459    [{"time":null,"date":null}]
"Valk 3"    "QiYi MoFangGe" "3x3"   7454    [{"time":null,"date":null}]
"Mini Rose Valk 3"  "QiYi MoFangGe" "3x3"   7456    [{"time":null,"date":null}]
"Valk 2"    "QiYi MoFangGe" "2x2"   7450    [{"time":null,"date":null}]
"ChuWen M"  "Supernova" "2x2"   7484    [{"time":null,"date":null}]
"Wingy" "X-Man Designs" "Skewb" 7457    [{"time":"12.255","date":1553881012244},{"time":"13.49","date":1553212800000}]
"Bell"  "X-Man Designs" "Pyraminx"  7478    [{"time":"9.234","date":1553817600000}]
"Ruipo" "YJ"    "2x2"   7451    [{"time":null,"date":null}]
"Little Magic"  "YuXin" "3x3"   7455    [{"time":null,"date":null}]

我不希望[[{“ time”:null,“ date”:null}]到达的目标

有任何想法吗? 谢谢,让我知道!

这应该以降序对日期进行排序,并在没有日期的times返回[]

MATCH (a:App{name:'AllAboutCubes'})<-[:MEMBER_OF]-(p:Cuber) WHERE id(p) = 1234
MATCH (p)<-[:BELONGS_TO {is_active:1}]-(c:Cube)
OPTIONAL MATCH (c)<-[:RECORDED_ON]-(t:Time)-[:RECORDED]-(p)
WITH c, t ORDER BY t.date DESC
OPTIONAL MATCH (c)-[:TYPE]->(ct:CubeType)
WITH c, ct, CASE WHEN t IS NULL THEN [] ELSE COLLECT({time:t.time,date:t.date}) END as times
RETURN c.name as name, c.manufacturer as manufacturer, ct.type as type, id(c) as cube_id, times
ORDER BY manufacturer

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM