cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Aggregation on non existant label

mithun_das
Graph Buddy

I have two labels Searchable and Unsearchable on one of my node...
Right now I have only Searchable nodes... So wanted to get counts of Unsearchable and assume that I will get 0. So my query was

optional match (c:Country) 
return 
   count(c) as countries, 
   count(c:Unsearchable) as unsearchableCountries

i assumed result should be

countries: 10 (as I have 10 countries marked as Searchable)
unsearchableCountries: 0 (as right now i have no Unsearchable country)

but I get 10 for both the values.
Can someone please help... what I am doing wrong?

1 ACCEPTED SOLUTION

mithun_das
Graph Buddy

I solved it using sum and case

optional match (c:Country) 
return 
   count(c) as countries, 
   sum(CASE WHEN c:Unsearchable THEN 1 ELSE 0 END) as unsearchableCountries

View solution in original post

1 REPLY 1

mithun_das
Graph Buddy

I solved it using sum and case

optional match (c:Country) 
return 
   count(c) as countries, 
   sum(CASE WHEN c:Unsearchable THEN 1 ELSE 0 END) as unsearchableCountries