When using the neo4j database, you will encounter the need to calculate the number of statistics associated with a specified node, for example, specify 6 nodes 1,2,3,4,5,6 need to find out the nodes associated with 4 of these 6 nodes (the requirement to exclude the data of these 6 nodes)
Let's look at implementing the query statement first:
MATCH (start:person_info)-[r1]-(n)-[r2]-(end:person_info) WHERE in ['1','2','3','4','5','6'] and in ['1','2','3','4','5','6'] and <> and <> and <> WITH collect() + collect() AS ids, AS idMidle UNWIND ids AS id WITH collect(DISTINCT id) AS countId,idMidle where length(countId)>=4 RETURN countId, idMidle
In the above statement
person_info:is an entity table
r1:It's their relationship.
['1','2','3','4','5','6']:given6of a nodeidhorn (wind instrument)
Statement Ideas:
1、consultations with6Individuals are related.,in that casestart:person_infocap (a poem)end:person_info It has to be this.6Entities in nodes。
2、start,n,end Three nodes cannot be equal。
3、commander-in-chief (military)startcap (a poem)endNodes are put into a collectioncollect() + collect() AS ids
4、Remove duplicates from a collection UNWIND ids AS id WITH collect(DISTINCT id)
5、The number of nodes in the set is greater than or equal to4is the node to be looked up
6、return to the same place as6nodes4of a node with which a node is associated,nodalid以及产生关系的nodal的idset (mathematics)
The red part above is,Combining two sets,And key points for de-duplicating data。