【发布时间】:2013-01-24 07:51:25
【问题描述】:
我的列表中有以下项目:
Date Amount AnId AnotherId MainDate
2013/01/10 1000 1 5 2013/01/12
2013/01/11 2000 2 5 2013/01/12
2013/01/15 4000 1 5 2013/01/12
我想使用 linq 返回以下内容:
Date Amount AnId AnotherId MainDate
2013/01/11 2000 2 5 2013/01/12
2013/01/15 4000 1 5 2013/01/12
即对于特定的MainDate,我只想要在AnId 和anotherId 中唯一的最新项目。因此,2013 年 1 月 10 日的项目被删除,因为同一 MainDate、AnId 和 AnotherId 的项目的日期晚于项目日期...
我一直在尝试Group By MainDate 和 Then By AnId 和 AnotherId 和 OrderByDescending 然后选择每个组的第一项,但对 linq 不太了解,所以我很挣扎......
【问题讨论】:
-
请使用您尝试过的 Linq 和 lambdas 添加您的 C#/VB 代码,但没有得到您希望的结果。这样我们就更容易看出哪里出了问题。
-
Group By Multiple Columns 的可能重复项