2

How do I make the equivalent of a this left join in cypher, but returning a single row for each activity? (Assume only 1 optional target record and one optional source record per activity - both can be present or absent etc)

person-----activity--+--> source (optional table, left join)
                     +--> target(optional table, left join)

of course I don't want two rows if a source and target exists, so this would be rolled up via crosstab /pivot table query so the final row would be

person...activity...(optional source node)...(optional target node)   

I want to bring back the person, activity, and optionally the source and target rows if they even exist - if not, just the person and activity.. I want one row per activity.

See the graph example at: http://console.neo4j.org/?id=rogg0w

Here is my guess as how to accomplish this

start n=node(1)
match n-[act_rel]->activity-[?sourcerel]-(source)
with n
match n-[act_rel]->activity-[?targetrel]-(target)
return n, activity, source.description! as description, target.description! as target_description

Basically I'd like to bring back a person's list of activities with optional source and target nodes on a single row for each activity - is this possible to do through Cyhper alone? (Using ROR / REST). What is wrong with the Cypher query above? Or must I get the person and activity data from cyper, and then look up nodes individually via code which would be, IMO, a big performance hit.

4

1 回答 1

3

您可以使用逗号来指定模式的多个部分:

start n=node(1)
match n-[:act_rel]->activity-[?:sourcerel]-source, activity-[?:targetrel]-target
return n, activity, source.description as description, target.description as target_description

说得通?

于 2013-08-02T16:18:46.120 回答