counting node properties

10 views
Skip to first unread message

Clark Richey

unread,
Apr 19, 2016, 4:45:25 PM4/19/16
to ne...@googlegroups.com
hi! I’m running neo 2.3 and I have a node, call it a Shoe with (for example) two properties, color and size. I have a cypher query that finds the shoes people bought on a given day. What I want to know is the count of shoes with distinct sizes and the count of shoes with distinct colors. I can easily get that information via 2 separate queries. I can also get the count of distinct combinations of size / color pairings but that isn’t what I want. 
Is there a way to get the counts of shoes with distinct sizes and the count of shoes with distinct colors in a single query?

Benoit Simard

unread,
Apr 19, 2016, 5:37:43 PM4/19/16
to ne...@googlegroups.com
Hi,

You can't make two distinct aggregation on one query, so you have to make 2 queries.

But you can join your queries result with UNION.

Cheers


Le 19/04/2016 22:45, Clark Richey a écrit :
hi! I’m running neo 2.3 and I have a node, call it a Shoe with (for example) two properties, color and size. I have a cypher query that finds the shoes people bought on a given day. What I want to know is the count of shoes with distinct sizes and the count of shoes with distinct colors. I can easily get that information via 2 separate queries. I can also get the count of distinct combinations of size / color pairings but that isn’t what I want. 
Is there a way to get the counts of shoes with distinct sizes and the count of shoes with distinct colors in a single query?

--
You received this message because you are subscribed to the Google Groups "Neo4j" group.
To unsubscribe from this group and stop receiving emails from it, send an email to neo4j+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Eve Freeman

unread,
Apr 22, 2016, 5:33:31 AM4/22/16
to ne...@googlegroups.com
Can you give an example output?

There are two ways I typically do this:
- collect the field I don't want to aggregate along with the count, then later unwind and count it while collecting the first field.
- Collect both fields, then write a collection function aggregation with reduce or something.

Eve 

Michael Hunger

unread,
Apr 22, 2016, 3:31:27 PM4/22/16
to ne...@googlegroups.com
I agree with Eve


Return size(collect(distinct color))) as colors, size(collect(distinct size))) as sizes


Von meinem iPhone gesendet
Reply all
Reply to author
Forward
0 new messages