Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
10-19-2022 01:53 PM
I successfully ran a simple optimization query for a single project: ‘Project A’ and got 2 set of lists
List 1: Employee label {Employee A, Employee B, Employee C}
List 2: Relationship property Hours {50,60,10}
My objective is to create relationship between Project and Employee and set Hours as a property.
Employee A will_work 50 hours on Project A
Employee B will_work 60 hours on Project A
Employee C will_work 10 hours on Project A
Without success I tried nested FOREACH just to receive a cartesian results (9 options).
Solved! Go to Solution.
10-20-2022 10:02 AM
That can be several approaches to solve this depending on how your are setting up the data. He is an example of a way to approach it. Do you have your entire query that we can look at to modify it? Do you intend to read the data from a spreadsheet?
with ["A", "B", "C"] as employees, [50, 60, 10] as hours
unwind range(0,size(employees)-1) as index
merge(e:Employee{name:employees[index]})
merge(p:Project{name:"A"})
merge(e)-[r:WILL_WORK]->(p)
SET r.hours=hours[index]
return e, p
10-19-2022 03:39 PM
You can get the Cartesian product between two lists with a double unwind, as follows:
with ["A", "B", "C"] as employees, [50, 60, 10] as hours
unwind employees as employee
unwind hours as hour
return employee, hour
Are you looking to create those three relationships from list1 and list2?
10-20-2022 06:52 AM
Thank you again for taking the time, after rereading my request I realized that I didn't do a good job describing the issue.
My objective is to avoid a cartesian query and unwind the two lists and create relationship.
the desired result are 3 relationships (not 9) :
Employee A will_work 50 hours on Project A
Employee B will_work 60 hours on Project A
Employee C will_work 10 hours on Project A
this is a "test" that I ran without success to set a property (Temp) on Employee label
so to summarize I need to unwind two coordinated list and create 3 relationships and set accordingly Hours.
(Employee)-[will_work]->(Project A)
SET Hours=vHRS
10-20-2022 10:02 AM
That can be several approaches to solve this depending on how your are setting up the data. He is an example of a way to approach it. Do you have your entire query that we can look at to modify it? Do you intend to read the data from a spreadsheet?
with ["A", "B", "C"] as employees, [50, 60, 10] as hours
unwind range(0,size(employees)-1) as index
merge(e:Employee{name:employees[index]})
merge(p:Project{name:"A"})
merge(e)-[r:WILL_WORK]->(p)
SET r.hours=hours[index]
return e, p
10-21-2022 12:26 PM
This is amazing , thank you for taking the time.
All the sessions of the conference are now available online