gpt4 book ai didi

average - 关于reduce part of RavenDB index, average calculation的语法问题

转载 作者:行者123 更新时间:2023-12-01 03:34:42 26 4
gpt4 key购买 nike

我正在努力寻找平均列的正确语法。我所拥有的——来自 RavenDB Studio 编辑器:

map :

from area in docs.Level5_AdministrativeAreas
select new
{
area.NAME_4,
totalPrice = area.pricePerSquareMetre,
areaCount = 1,
priceAverage = 0
}

减少:

from result in results
group result by new { result.NAME_4 } into g
select new
{
NAME_4 = g.Key.NAME_4,
totalPrice = g.Sum(x => x.totalPrice),
areaCount = g.Sum(x => x.areaCount),
priceAverage = totalPrice / areaCount
}

计数和总价计算正确,但我不知道如何引用 totalPriceareaCount

是否需要额外的选择 block ?我尝试了“g.totalPrice”和“g.priceAverage”,但无法识别。

感谢您的帮助!

最佳答案

Reduce部分需要像这样:

减少:

from result in results
group result by new { result.NAME_4 } into g
let theCount = g.Sum(x => x.areaCount)
let theTotal = g.Sum(x => x.totalPrice)
select new
{
NAME_4 = g.Key.NAME_4,
totalPrice = theTotal,
areaCount = theCount ,
priceAverage = theTotal / theCount
}

=> 阅读部分 Common Pitfalls with MapReduce Indexes

关于average - 关于reduce part of RavenDB index, average calculation的语法问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60454227/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com