按Neo4J数据库中的多个属性计算节点

k5hmc34c  于 2022-11-05  发布在  其他
关注(0)|答案(1)|浏览(208)

我有一个Neo4J数据库,其结构如下图所示。x1c 0d1x它表示来自一所学校的人。我希望有一个查询,允许我计算多个属性/标签上的节点。
我需要这样的回应。

{
  teachers: 2,
  staff: 5,
  students: {
    total: 3,
    overNine:1,
    overEight:1,
    over seven:1
  },
  peopleInSchool:[
    {
      name: name1,
      details: someDetailedProperty1
    },
    {
      name: name2,
      details:someDetailedProperty2
    }
  ]

}
wbgh16ku

wbgh16ku1#

你可以尝试以下几种方法:

MATCH (n) 
WITH COLLECT(n) AS nodes
WITH nodes, 
size([x IN nodes WHERE x:Staff | x]) AS staff, size([x IN nodes WHERE x:Teacher | x]) AS teacher, 
size([x IN nodes WHERE x:Student | x]) AS student, size([x IN nodes WHERE x:Student AND x.avg > 7 AND x.avg < 8 | x]) AS overSeven,  
size([x IN nodes WHERE x:Student AND x.avg > 8 AND x.avg < 9 | x]) AS overEight,
size([x IN nodes WHERE x:Student AND x.avg > 9 | x]) AS overNine
RETURN { teachers: teacher, staff: staff, students: { total: student, overSeven: overSeven, overEight: overEight, overNine: overNine }}

在这里,我们提取所有节点并将它们收集到列表中,然后在筛选元素后计算列表的大小,匹配一定的条件。例如:
size([x IN nodes WHERE x:Staff | x])
此语句计算列表的大小,其中只存在staff节点。

相关问题