我有一张表,记录了我们公司客户列表中发生的所有事情。这就是它的样子:
Company CompanyType Change_Dt Chng_Type
Apple Large 12/12/2012 A
Dell Large 12/01/2012 A
Adobe Mid 06/12/2012 A
Dell Large 11/01/2012 D
eBay Small 11/02/2012 A
Apple Large 10/29/2012 D
Dell Large 10/20/2012 A
eBay Small 10/02/2012 D
3M Small 09/02/2012 D
Adobe Mid 05/30/2012 D
问题在于有很多公司类型,我只想保留一份最新“A”公司的名单。最后,我应该有一个看起来像的列表:
CompanyType Company Change_Dt Chng_Type
Large Apple 12/12/2012 A
Large Dell 12/01/2012 A
Mid Adobe 06/12/2012 A
Small eBay 11/02/2012 A
到目前为止我的查询是:
table.OrderBy(t => CompanyType).Where(t => Chng_Type.Equals("A"))
如何完成查询?提前谢谢。
答案 0 :(得分:2)
var query = table.Where(t => t.Chng_Type.Equals("A"))
.GroupBy(t => t.Company)
.Select(g => g.OrderByDescending(t => t.Change_Dt)
.FirstOrDefault());
说明: