我试图获得两个属性总和(带有权重)并最终将它们组合成一个组合权重。
因此,首先是单独的查询,因此您可以看到正确的总和权重
Language = French
,熟练程度超过6(1-10级):
MATCH (User)-[Speaks]->(Language)
WHERE Language.language = 'French' AND Speaks.proficiency >=6
RETURN User.name, SUM(
CASE
WHEN Language.language='French' THEN Speaks.proficiency*3
END )*0.1 AS TOTAL_Language
ORDER BY TOTAL_Language DESC
User.name TOTAL_Language 大卫3 Marion 1.8
Skill = Finance,Banking,IT,Marketing Weight =1 (of 1)
:
MATCH (User)-[IsSkilledIn]->(Skill)
WHERE Skill.skill IN ['Finance','Banking','IT','Marketing']
RETURN User.name, SUM(
CASE
WHEN Skill.skill='Finance' THEN IsSkilledIn.weight*10
WHEN Skill.skill='Banking' THEN IsSkilledIn.weight*5
WHEN Skill.skill='IT' THEN IsSkilledIn.weight*8
WHEN Skill.skill='Marketing' THEN IsSkilledIn.weight*1
END )*0.1 AS TOTAL_Skill
ORDER BY TOTAL_Skill DESC
User.name TOTAL_Skill
Eric 1.5
Marion 0.9
David 0.8
Hans 0.8
所以现在,我尝试将这些查询组合成:
French >=6 AND Skills Finance,Banking,IT,Marketing
:
MATCH (User)-[Speaks]->(Language) , (User)-[IsSkilledIn]->(Skill)
WHERE Language.language = 'French' AND Speaks.proficiency >=6 AND Skill.skill IN ['Finance','Banking','IT','Marketing']
RETURN User.name, SUM(
CASE
WHEN Language.language='French' THEN Speaks.proficiency*3
END )*0.1 AS TOTAL_Language,
SUM(
CASE
WHEN Skill.skill='Finance' THEN IsSkilledIn.weight*10
WHEN Skill.skill='Banking' THEN IsSkilledIn.weight*5
WHEN Skill.skill='IT' THEN IsSkilledIn.weight*8
WHEN Skill.skill='Marketing' THEN IsSkilledIn.weight*1
END )*0.1 AS TOTAL_Skill
ORDER BY TOTAL_Skill DESC
现在我得到了这些结果:
User.name TOTAL_Language TOTAL_Skill
Marion 3.6 0.9
David 3 0.8
马里昂的TOTAL_Language
是第一个答案的两倍。
所以我检查了什么可能是错的,它必须在WHERE-Clause中,但我不知道什么是错的。
我怎样才能总结两个结果?
答案 0 :(得分:1)
MATCH (User)-[Speaks]->(Language)
WHERE Language.language = 'French' AND Speaks.proficiency >=6
WITH User, SUM(
CASE
WHEN Language.language='French' THEN Speaks.proficiency*3
END )*0.1 AS TOTAL_Language
MATCH (User)-[IsSkilledIn]->(Skill)
WHERE Skill.skill IN ['Finance','Banking','IT','Marketing']
RETURN User.name, TOTAL_Language, SUM(
CASE
WHEN Skill.skill='Finance' THEN IsSkilledIn.weight*10
WHEN Skill.skill='Banking' THEN IsSkilledIn.weight*5
WHEN Skill.skill='IT' THEN IsSkilledIn.weight*8
WHEN Skill.skill='Marketing' THEN IsSkilledIn.weight*1
END )*0.1 AS TOTAL_Skill
ORDER BY TOTAL_Skill DESC
答案 1 :(得分:1)
另一个选择是仍然使用一个查询,但收集一个人的技能,并总结技能权重的集合,而不是对行进行求和,
MATCH (User)-[Speaks]->(Language), (User)-[IsSkilledIn]->(Skill)
WHERE Language.language = 'French'
AND Speaks.proficiency >=6
AND Skill.skill IN ['Finance','Banking','IT','Marketing']
WITH User.name as userName,
(CASE WHEN Language.language='French'
THEN Speaks.proficiency*3 END) as languageProficiency,
collect(CASE
WHEN Skill.skill='Finance' THEN IsSkilledIn.weight*10
WHEN Skill.skill='Banking' THEN IsSkilledIn.weight*5
WHEN Skill.skill='IT' THEN IsSkilledIn.weight*8
WHEN Skill.skill='Marketing' THEN IsSkilledIn.weight*1
END) as skillWeightCollection
RETURN userName,
sum(languageProficiency)*0.1 as TOTAL_Language,
reduce(totalSkill = 0, skillWeight in skillWeightCollection |
totalSkill + skillWeight) * 0.1 as TOTAL_SKILL