问题
Considering the existence of three types of nodes in a db, connected by the schema
(a:a)-[ra:madeWithB {ra.qty}]->(b:b)-[rb:madeWithC {rb.qty}]->(c:c)
with the user being able to have connection with each one of these types.
(user)-[:has {qty}]->(a:a)
(user)-[:has {qty}]->(b:b)
(user)-[:has {qty}]->(c:c)
What would be the best way to query the database to return a list of all the nodes the user :has, considering that when he :has an (a)
then in the result the associated (b)
and (c)
should also be returned after having multiplied their qty field?
Real world example: a user buys three IKEA fully furnished rooms (nodes a
). The db knows what furniture's in them (b
nodes) and what parts are needed for those items (nails & stuff, c
nodes). The user also buys some other random furniture (ie: some more b
nodes, without being connected to any a
but being connected to more c
) and some extra spare nails and other parts (ie: some more c
nodes, not connected to any b
).
So - knowing the list of a
and additional b
and c
- print the list of all b
(that will be the sum of those contained in the three rooms + extra) and c
(that will be the parts needed for all the furniture and extra), with its associated qty.
NOTE: consider arbitrary length queries not to be an option when matching nodes.
来源:https://stackoverflow.com/questions/22369865/neo4j-cypher-stacking-nodes-from-sequential-query-results