我有一个列表(pk = Id)。该表有一个由PracticeProfileId提供的practicticeprofile的FK (即1个Practice profile有许多清单)
我想返回每个practice profile的平均列表数
int count;
count = (from l in myentity.Listings
group l by l.PracticeProfileId into g
select g.Count()).Average();我想我已经成功地通过practiceprofile对列表进行了分组,但是我不确定如何获得列表的总平均数量
谢谢
发布于 2012-04-05 20:38:59
你应该使用Group By,试着按照下面的例子操作:
var categories =
from p in products
group p by p.Category into g
select new { Category = g.Key, AveragePrice = g.Average(p => p.UnitPrice) }; 发布于 2012-08-18 01:35:10
我想包括每一类产品的数量,以及平均单价。我找不到正确的语法。
var categories =
from p in products
group p by p.Category
into g
select new { Category = g.Key,
ProdsInCat = g.Count(),
AveragePrice = g.Average(p => p.UnitPrice) }; 编辑后添加:
这是正确的语法。我发现了错误;我将ProdsInCat定义为String而不是Int。
https://stackoverflow.com/questions/10028621
复制相似问题