Cypher查询需求:HPKP节点关联Issue的属性求和与分组过滤
Cypher Query to Calculate Total Worklog for HPKP-X Associated Nodes (Excluding
relates Relationships) Got it, let's refine your query to hit exactly what you need. Here's the polished solution:
Final Cypher Query
MATCH c = (p:Project{key:"HPKP"})-[r:CONTAINS]->(hpkpXIssue:Issue)-[*]-(relatedIssue:Issue) WHERE NONE(rel IN relationships(c) WHERE type(rel) = 'relates') RETURN hpkpXIssue.key AS hpkpXNode, SUM(relatedIssue.worklog) AS totalWorklog GROUP BY hpkpXIssue.key
Step-by-Step Breakdown
- MATCH Clause: We start at the
Projectnode with key "HPKP", traverse theCONTAINSrelationship to grab its direct child issues (your HPKP-X nodes). Then we match all arbitrary-depth paths from these HPKP-X nodes to otherIssuenodes. - WHERE Clause: The
NONE()function acts as a filter to ensure no relationship in the entire pathcis of typerelates—this cuts out any paths that include the unwanted relationship type entirely. - RETURN + GROUP BY: We group results by each HPKP-X node's key, then calculate the sum of the
worklogproperty from all associatedrelatedIssuenodes.
Optional: Exclude the HPKP-X Node Itself
If you don't want the HPKP-X node's own worklog included in the total, add an extra condition to the WHERE clause:
MATCH c = (p:Project{key:"HPKP"})-[r:CONTAINS]->(hpkpXIssue:Issue)-[*]-(relatedIssue:Issue) WHERE NONE(rel IN relationships(c) WHERE type(rel) = 'relates') AND hpkpXIssue <> relatedIssue RETURN hpkpXIssue.key AS hpkpXNode, SUM(relatedIssue.worklog) AS totalWorklog GROUP BY hpkpXIssue.key
This ensures we only sum worklogs from nodes connected to HPKP-X, not the HPKP-X node itself.
内容的提问来源于stack exchange,提问作者Eugen
相关产品推荐
相关产品推荐

