Cypher聚合在路径子集上

时间:2016-05-17 13:22:04

标签: neo4j cypher aggregate

我有以下图表,并且有兴趣从a1开始获取叶子节点的所有金额的总和。

enter image description here

但是,使用cypher时,它会考虑所有路径,最终结果是使用SUM查询而不是12。 例如。

From: file:///C:/Program Files (x86)/EasyGrammar/EasyGrammar/EasyGrammar.vsto

************** Exception Text **************
System.ArgumentException: Value does not fall within the expected range.
   at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)
   at System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(Int32 errorCode)
   at Microsoft.VisualStudio.Tools.Office.Runtime.Interop.VSTOEENativeMethods.GetValidCompatibleFramework(String compatibleFrameworkXml)
at Microsoft.VisualStudio.Tools.Office.Runtime.CompatibleFrameworksValidation.ParseFirstValidFramework(String compatibleFrameworksXml)
   at Microsoft.VisualStudio.Tools.Office.Runtime.OfficeAddInDeploymentManager.OnAddInManifestsDownloaded(AddInManifestsDownloadedArgs args)
   at Microsoft.VisualStudio.Tools.Applications.Deployment.ClickOnceAddInDeploymentManager.RaiseOnAddInManifestsDownloadedEvent(IClickOnceAddInInstaller addInInstaller, Uri deploymentManifestUri, AddInInstallationStatus addinSolutionState, String productName, String deploymentManifestXml, String applicationManifestXml, String hostManifestXml, String logFilePath, String version, Uri supportUri)
   at Microsoft.VisualStudio.Tools.Applications.Deployment.ClickOnceAddInDeploymentManager.InstallAddIn()

我的查询应该是什么样的?

这是创建图表的密码。

节点:

match (:A {name:'a1'})<-[:BA]-(:B)-[:BC]->(c:C)-[cd:CD]->(d:D)
return d.name, SUM(cd.amount)

RELS:

create (a1:A {name:'a1'}), (b1:B {name:'b1'}), (b2:B {name:'b2'}),
(c1:C {name:'c1'}), (c2:C {name:'c2'}), (d1:D {name:'d1'})

1 个答案:

答案 0 :(得分:0)

感谢@TimKuehn提供的'独特'提示。

此查询有效:

MATCH (:A {name:'a1'})<-[:BA]-(:B)-[:BC]->(c:C)-[cd:CD]->(d:D) 
WITH DISTINCT d.name AS dname, cd 
RETURN dname, SUM(cd.amount) as total
相关问题