cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Help on building a query

kleysonr
Node Link

I have modeled an schema for an internal business process.

Below an example of my data:

In the example above John works for two different companies, but for the given process he used both companies' logins to interact in the same process.

My question is: How can I query all the Process where both logins of John was used in the same process ?

Below a cypher query that I was playing without success.

MATCH (person:Person {name: "John"}),
      (company1:Company {name: "Company2"}),
      (company2:Company {name: "Company3"}),
      (person)-[:WORKS_FOR]->(company1),
      (person)-[:WORKS_FOR]->(company2),
      (person)<-[c:CHANGED_BY]-(e:Event),
      (e)-[p:BELONGS_TO]->(process:Process)
WHERE
  (company1.name = c.company_name or company2.nome = c.company_name)
RETURN DISTINCT person.name AS Person, company1.name AS Company1, Company2.name AS Company2, process.id AS ProcessNro
1 ACCEPTED SOLUTION

@kleysonr as my answer's note said, the result returned by cypher query is not filtered by company's name. To do so put the below where:

MATCH (p:Person {name: "John"})-[:WORKS_FOR]->(c:Company),
      (e:Event)-[:CHANGED_BY]->(p),
      (e)-[:BELONGS_TO]->(pss:Process)
WHERE c.name IN ["Company 2","Company 3"]
RETURN {name:p.name,companies:COLLECT(DISTINCT c.name),processes:COLLECT(DISTINCT pss.id)} As result

View solution in original post

3 REPLIES 3

jhakiz
Node Link

@kleysonr The below cypher query may respond to your question:

MATCH (p:Person {name: "John"})-[:WORKS_FOR]->(c:Company),
      (e:Event)-[:CHANGED_BY]->(p),
      (e)-[:BELONGS_TO]->(pss:Process)
RETURN {name:p.name,companies:COLLECT(DISTINCT c.name),processes:COLLECT(DISTINCT pss.id)} As result

Note that John is working in two or more Companies;
The above cypher query is not filtered by company's name but they are returned in array(all affected companies names).

kleysonr
Node Link

@jhakiz Thanks for the answer, but the query is bringing all the process where John is connected.

I'm looking for a different answer.

Based on the image above, John works for 2 companies at the same time. But for the process XT02145-1 he did a login using his account of Comapny 2 and did some change on the process. Then he did a logout of Company 2 and did a new login using his account of Company 3 and again changed the process.

I'm looking for all the process where John had the same behavior. So, he used different accounts to execute different actions in the same process.

@kleysonr as my answer's note said, the result returned by cypher query is not filtered by company's name. To do so put the below where:

MATCH (p:Person {name: "John"})-[:WORKS_FOR]->(c:Company),
      (e:Event)-[:CHANGED_BY]->(p),
      (e)-[:BELONGS_TO]->(pss:Process)
WHERE c.name IN ["Company 2","Company 3"]
RETURN {name:p.name,companies:COLLECT(DISTINCT c.name),processes:COLLECT(DISTINCT pss.id)} As result