linq 多表分组查询统计
Posted 吴晓阳
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了linq 多表分组查询统计相关的知识,希望对你有一定的参考价值。
var q1 = from orderitem in q2 join pd in _iProductDetailContract.Entities on orderitem.ProductDetailId equals pd.Id join pm in ProductMainContract.Entities on pd.ProductMainId equals pm.Id join user in UserContract.Entities on pm.BuyerId equals user.Id into orderItemBuyer from user in orderItemBuyer.DefaultIfEmpty() group new { orderitem.Price, orderitem.Num } by new { orderitem.ProductDetailId, orderitem.Name, orderitem.Size, orderitem.Price, pm.AliasName, BuyerName = user.Name } into g orderby g.Sum(p => p.Num) descending select new { ProductDetailId = g.Key.ProductDetailId, Name = g.Key.Name, Size = g.Key.Size, AliasName = g.Key.AliasName, BuyerName = g.Key.BuyerName, Num = g.Sum(p => p.Num), Price = g.Key.Price, TotlePrice = g.Sum(p => p.Num * p.Price) } ;
以上是关于linq 多表分组查询统计的主要内容,如果未能解决你的问题,请参考以下文章