我想计算每种职业的每种技能的百分比。 我做了a有不同的节点占用和Soft_skills它们有关系[r:MAPS_TO]该关系有两个属性类型('essentieel','optioneel')和b(这种权重essentieel = 1.0和optioneel = 0.5)
请参阅下面我正在使用的文件的示例
职业 | 代码_职业 | 技能代码 | 名字 | 类型 | b |
---|---|---|---|---|---|
博士 | sk_565 | sk_687 | 勒伦 | 选项 | 0.5 |
博士 | sk_565 | sk_687 | 勒伦 | 选项 | 0.5 |
博士 | sk_565 | sk_687 | 勒伦 | 精华 | 1.0 |
博士 | sk_565 | sk_687 | 勒伦 | 精华 | 1.0 |
我做了一个查询,我可以计算每个职业的总和,请参阅下面的查询:
match (b:BOC_beroep)-[r:MAPS_TO]-(s:Soft_Skill)
return b.beroepstitel as beroep,
sum(toFloat(r.b)) as sum order by sum desc
limit 10
这是我的输出
贝罗普 | 总和 |
---|---|
多克 | 5 |
卡珀 | 7 |
知道我想要达到我计算的技能类型的百分比
Dokter have in total 4 skills en the percentage of each skill is
2/4 * 100 = 50% essentieel
1/4 * 100 = 25% optioneel
i was trying to make a new calculation with this query:
MATCH (b:BOC_beroep)-[r:MAPS_TO]->(s:Soft_skill)
WITH SUM(toFloat(r.b)) As total
MATCH (b:BOC_beroep)-[r:MAPS_TO]->(s:Soft_Skill)
RETURN b.beroepstitel AS beroep,
(toFloat(total/(r.b)))*100 AS percent
order by percent desc
我的输出是 Cannot split 'Long' by 'string' 我不明白这个错误
我受到这个问题和答案的启发 这是指向 stackoverflow 的内联链接。
据我了解,您可能想要这样的东西:
MATCH (b:BOC_beroep)-[r:MAPS_TO]->(s:Soft_Skill)
WITH SUM(1) AS total, r.type AS type, COLLECT(r.b) AS type_sum
WITH REDUCE(total=0, number in type_sum | total + number) AS type_sum, type, total
WITH COLLECT ({type: type, type_sum: toFloat(type_sum)}) AS data, SUM(total) AS total
UNWIND data AS d
WITH d.type_sum / total * 100 AS percent, d.type AS type
RETURN percent, type
ORDER BY percent DESC
样本数据:
MERGE (a1:BOC_beroep {occupation: 'dokter', code_occupation: 'sk_565'})
MERGE (a2:Soft_Skill {skill_code: 'sk_687', name: 'leren'})
MERGE (a1)-[:MAPS_TO{type:"optioneel", b:0.5, k:1}]-(a2)
MERGE (a1)-[:MAPS_TO{type:"optioneel", b:0.5, k:2}]-(a2)
MERGE (a1)-[:MAPS_TO{type:"essentieel", b:1, k:3}]-(a2)
MERGE (a1)-[:MAPS_TO{type:"essentieel", b:1, k:4}]-(a2)
退货:
╒═════════╤════════════╕
│"percent"│"type" │
╞═════════╪════════════╡
│50.0 │"essentieel"│
├─────────┼────────────┤
│25.0 │"optioneel" │
└─────────┴────────────┘