英文:
Neo4j Cypher Group By
问题
如何继续查询以返回c
的s
和每个不同s
的计数?
英文:
I have the following Cypher query:
MATCH (c:Criterion {id: 24})
OPTIONAL MATCH (c)<-[:HAS_VOTE_ON]-(d:Decision)-[:HAS_VOTE_ON]->(s:Skill)
WHERE s.id <> c.id WITH c, s
How to continue the query in order to return for c
: s
and count of each distinct s
?
答案1
得分: 1
你需要同时收集并计数s,然后如果要继续处理每个单独的s节点,就需要将收集的内容解析回单独的行。
MATCH (c:Criterion {id: 24})
OPTIONAL MATCH (c)<-[:HAS_VOTE_ON]-(d:Decision)-[:HAS_VOTE_ON]->(s:Skill)
WHERE s.id <> c.id
WITH c, collect(DISTINCT s) as skills, count(DISTINCT s) as count
UNWIND skills as s
...
英文:
You would need to collect and count s at the same time, then UNWIND the collection back into individual rows if you want to continue with each individual s node.
MATCH (c:Criterion {id: 24})
OPTIONAL MATCH (c)<-[:HAS_VOTE_ON]-(d:Decision)-[:HAS_VOTE_ON]->(s:Skill)
WHERE s.id <> c.id
WITH c, collect(DISTINCT s) as skills, count(DISTINCT s) as count
UNWIND skills as s
...
答案2
得分: 1
If you just want to return each distinct s
and its count:
匹配(c:标准{ id:24 })& lt; -[:HAS_VOTE_ON]-(:决策)-[:HAS_VOTE_ON]-& gt;(s:技能)
其中 s.id & lt; & gt; c.id
返回 s,COUNT(*) AS cnt
英文:
If you just want to return each distinct s
and its count:
MATCH (c:Criterion {id: 24})<-[:HAS_VOTE_ON]-(:Decision)-[:HAS_VOTE_ON]->(s:Skill)
WHERE s.id <> c.id
RETURN s, COUNT(*) AS cnt
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论