0

I have Nodes Customer and Product - with a directed relationship TRANSACTION from Customer to Product. Product has the property category.

Is it possible to display all the Customers connected to all the categories which they have bought? As though the categories were a node rather than a property.

D10001
  • 123
  • 1
  • 1
  • 7

1 Answers1

1

You can use APOC Virtual Nodes and Relationships to display such graph :

MATCH (n:Product)<-[:TRANSACTION]-(c:Customer)
WITH n.category AS category, c, count(*) AS numberOfPurchases
WITH 
apoc.create.vNode(['Category'], {name: category}) AS catNode,
c,
numberOfPurchases
RETURN catNode, c, 
apoc.create.vRelationship(c, 'PURCHASED_IN_CATEGORY', {amount: numberOfPurchases}, catNode) AS rel
Christophe Willemsen
  • 19,399
  • 2
  • 29
  • 36