密码从结果中删除 null s

问题描述

我在 neo4j 中创建了一个查询

MATCH (x:Node)-[r*1..2]->(y:Node) 
WITH x AS x,SIZE(COLLECT(disTINCT y)) AS y
WITH CASE
    WHEN y=10 THEN x.target
END AS l
return l AS target

但返回类似:

target
____
null
null
"test1"
null
null
"tes56"
...

我想要的是:

target
____
"test1"
"tes56"
...

条目中没有空值。我怎样才能做到这一点?

解决方法

您在应该使用 WHERE 的时候使用了 CASE/WHEN(它不会过滤掉行)。

此外,size(collect(DISTINCT )) 实际上只是一个 count(DISTINCT ) 聚合,因此请改用它。

另外为了避免混淆,可以为计数结果使用不同的变量名。

MATCH (x:Node)-[*1..2]->(y:Node) 
WITH x,count(DISTINCT y) AS yCount
WHERE yCount = 10
RETURN x.target AS target