poorvank
poorvank

Reputation: 7612

Combine 2 cypher queries into 1

I am working with the graph database Neo4j. I want to combine the following two cypher queries into one.

START a=node(2)
MATCH (a)<-[:TYPE]-(vendrs)<-[:FROM]-(prods) 
RETURN vendrs.name, count(prods)

START a=node(2)
MATCH (a)<-[:TYPE]-(vendrs)<-[:FROM]-(prods)
WHERE(prods.r?<>-1 and prods.f?<=0 and prods.I! = 1) 
RETURN vendrs.name, count(prods)

Node with id 2 is a super node having nodes representing vendors related to it via TYPE relationships and from each of these nodes prods are related by FROM relationship.

I want to combine them into one so i tried:

START a=node(2)
MATCH (a)<-[:TYPE]-(vendrs)<-[:FROM]-(prods)
RETURN vendrs.name,
    count(prods),
    filter(count(prods) where(prods.r?<>-1 and prods.f?<=0 and prods.I! = 1));

But its not working? How should i correct it?

Error:SyntaxException: Unclosed parenthesis

Upvotes: 1

Views: 331

Answers (1)

Andrew Lank
Andrew Lank

Reputation: 1617

Not sure what version of Neo4j, but the filter I see with 2.0 is

FILTER(x IN coll WHERE x.prop <> {value})

so I'm going to assume that what you actually want is a count of those filtered products and not a FILTER() on the COUNT()?

COUNT(FILTER(product IN products WHERE product.r?<>-1 AND product.f?<=0 AND product.I! = 1)) AS filterCount

Haven't tried this but it makes sense. Also used to full name (product instead of prodct or what ever) just to make it clear to other readers. Note i'm not sure what the '!' is, and you might be better to check performance tips on Cypher regarding all the '?' optional prams if they really must be optional.

Upvotes: 1

Related Questions