0

我在 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"
...

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

4

1 回答 1

1

当您应该使用 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
于 2021-04-26T14:41:28.303 回答