Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
451 views
in Technique[技术] by (71.8m points)

cypher - neo4j - get attribute value from multiple related objects into one return row

I have the following situation:

MATCH (n) WHERE n.Type IN ['a', 'b', 'c'] WITH n OPTIONAL MATCH (f)-[:PART_OF]->(n) RETURN CASE WHEN n.Type = a THEN f.attribute WHEN n.Type = b then f.attribute1 ELSE '' END, n.type

I want one single row returned even if n has multiple objects related to it.

The below solution is not enough because I don't know the exact number of related objects. There could be 1..n relations from (f) - [:part_of] -> (n):

MATCH (n) WHERE n.Type IN ['a', 'b', 'c'] WITH n OPTIONAL MATCH (f)-[:PART_OF]->(n) WITH n, COLLECT({ftype: f.Type, fsubType:f.SubType}) AS ff RETURN CASE WHEN n.Type = a AND ff[0].ftype = x THEN 'z' .....

Thanks!

question from:https://stackoverflow.com/questions/65888048/neo4j-get-attribute-value-from-multiple-related-objects-into-one-return-row

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

MATCH (n) WHERE n.Type IN ['x', 'y'] WITH n OPTIONAL MATCH (f)-[:PART_OF]->(n) WITH n, COLLECT({ftype: f.Type, fsubtype:f.SubType, flocalipaddr: f.LocalIpAddr, fip: f.IP, fremotetunnelendpoint: f.RemoteTunnelEndpoint, fpeername: f.PEERNAME}) AS fcp WITH n, fcp, [x IN fcp WHERE x.ftype = 'IKEP' AND x.fsubtype = 'Security Gateway' and n.SubType = 'eNodeB'| x.fpeername] AS fpeername, [x IN fcp WHERE x.ftype = 'DEVIP' AND x.fsubtype = 'SYNC' and n.SubType = 'eNodeB'| x.fip] AS fip RETURN 'Base Station' AS OptType, n.SubType, fpeername[0], fip[0]


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...