我有一个大表,其中包含 6000000 条记录,例如这种格式(Acc,sDate,Serial,Amount,...) Acc,date,serial 是 PKey。
为了显示我的问题,创建了小代码
public class Cheque
{
public string Account{ get; set; }
public string Serial{ get; set; }
public string StartDate { get; set; }
// ... public string Amount { get; set; } ...
}
var list = new List<Cheque>();
list.Add(new Cheque() { Account= "1", Serial = "1", StartDate = "20080120"});
list.Add(new Cheque() { Account= "1", Serial= "2", StartDate = "20080120" });
list.Add(new Cheque() { Account= "1", Serial= "3", StartDate = "20080120" });
list.Add(new Cheque() { Account= "1", Serial= "4", StartDate = "20080120" });
// each acc have 100 to 300 record per date ,for simplicity 3 obj added
list.Add(new Cheque() { Account= "1", Serial= "1", StartDate = "20110120" });
list.Add(new Cheque() { Account= "1", Serial= "2", StartDate = "20110120" });
list.Add(new Cheque() { Account= "1", Serial= "1", StartDate = "20120120" });
list.Add(new Cheque() { Account= "1", Serial= "2", StartDate = "20120120" });
list.Add(new Cheque() { Account= "1", Serial= "3", StartDate = "20120120" });
list.Add(new Cheque() { Account= "2", Serial= "1", StartDate = "20100417" });
list.Add(new Cheque() { Account= "2", Serial= "2", StartDate = "20100417" });
list.Add(new Cheque() { Account= "2", Serial= "1", StartDate = "20120314" });
list.Add(new Cheque() { Account= "2", Serial= "1", StartDate = "20070301" });
list.Add(new Cheque() { Account= "2", Serial= "1", StartDate = "20070301" });
list.Add(new Cheque() { Account= "2", Serial= "1", StartDate = "20070301" });
预期的列表仅包含与每个帐户最近的日期
累积序列日期
"1", "1", "20120120" //first resultSet with Account= 1
"1", "2", "20120120"
"1", "3", "20120120"
"1", "1", "20110120" //second resultset with Account= 1
"1", "2", "20110120"
"2", "1", "20120314" //first resultSet with Account= 2
"2", "1", "20100417" //second resultset with Account= 2
"2", "2", "20100417"
请帮助我如何用 linq 查询这个如何按(或不同)分组并采取第一组,像这样