我有一个SQL查询。我无法将此查询转换为lambda。你能帮我把这个查询转换成lambda吗?
我有SELECT v.relationship, q.group_name, q.order_number, avg(a.value) from evaluation e
LEFT JOIN evaluator v on e.id = v.evaluation
LEFT JOIN answer a on v.id = a.evaluator
LEFT JOIN question q ON a.question = q.id
where e.id='b19e8a34-d786-11e6-89b9-38b1dbfd82dd'
GROUP BY v.relationship, q.group_name, q.order_number
ORDER BY v.relationship, q.order_number;
。我想从这个列表中得到answer.value的平均值。 Group by evaluator.relationship和question.groupName
SQL查询:
{{1}}
实体图:
答案 0 :(得分:0)
evaluators.stream()
.flatMap(evaluator -> evaluator.getAnswers().stream())
.collect(Collectors.groupingBy(
answer -> new AbstractMap.SimpleEntry<>(answer.getEvaluator().getRelationship(),
answer.getQuestion().getGroupName()),
Collectors.averagingInt(Answer::getValue)));
说明:
Stream<Answer>
。answer.evaluator.relationship
和answer.question.groupName
的对(使用AbstractMap.SimpleEntry)。Double
。所以你应该得到一个Map<Entry, Double>
。如果您愿意,也可以为密钥而不是String
创建Map.Entry
,但这可能会导致大量不必要的字符串连接。