neo4j cypher: stacking nodes from sequential query results

旧街凉风 提交于 2019-12-11 14:38:17

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!