日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Linq中的group by多表多字段,Sum求和

發布時間:2023/12/15 编程问答 40 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Linq中的group by多表多字段,Sum求和 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
Linq中的group by多表多字段,Sum求和 //Line to Sql 寫法
var data = (from a in Itemsgroup a by new { a.GroupId, a.Id } into b//orderby new ComparerItem() { GroupId = b.Key.GroupId, Id = b.Key.Id } descending
     .where(o => o.Id>1000)
select new{GroupId = b.Key.GroupId,Id = b.Key.Id,Count = b.Sum(c => c.Count),Weight = b.Sum(c => c.Weight)}).OrderBy(t => t.GroupId).ThenBy(t => t.Id);

items 是一個包含4個字段(GroupId, Id, Count, Weight)的list.

效果,按GroupId,Id 分組 ,并統計Count字段和Weight字段

//labmda 寫法var data = items.GroupBy( t=> t.GroupBy,t=> t.Id).where( f=> f.Id>1000).Select( g=> new {GroupId = g.GroupId,Id = g.Id,Count = g.Count( ),SumWeight = g.Sum( x=>x.Weight)});

?

//多表寫法from a in TableA join b in TableB on a.Id equals b.aId where ((b.Type == 1 || b.Type == 2 || b.Type == 5) && b.State == 1) group new { a.Id, b.Name,b,CreateDate } by new { a.Id, b.Name } into g select (new Class1 { Id = g.Key.Id, Name = g.Key.Name ?? "" }); class Class1 { public int Id { get; set; } publid string Name { get; set; } }

?

from c in Customersjoin p in Purchaseson c.ID equals p.CustomerIDgroup p.Price by new{p.Date.Year,c.Name}into salesByYearorderby salesByYear.Key.Year descendingselect new{TotalPrice= salesByYear.Sum(),Year=salesByYear.Key.Year,Name=salesByYear.Key.Name}

?

posted on 2017-04-07 11:45 szsunny 閱讀(...) 評論(...) 編輯 收藏

轉載于:https://www.cnblogs.com/sxypeace/p/6677424.html

總結

以上是生活随笔為你收集整理的Linq中的group by多表多字段,Sum求和的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。