我有一些数据,我想解析,然后基于此,我必须采取数据的日期是最小的每个组。
数据文件如下(一小段)
D_REPDATE;INDEX;MATLABEL;ST_START;ST_END;QT_START;QT_END;PRC_RF0;PRC_RF1
APR-13;04/01/13;F35MEDFC;APR-13;01/04/13;30/04/13;01/04/11;29/03/13;596.02000;596.02000
APR-14;04/01/13;F35MEDFC;APR-14;01/04/14;30/04/14;30/03/12;31/03/14;581.77000;581.77000
APR-15;04/01/13;F35MEDFC;APR-15;01/04/15;30/04/15;01/04/13;31/03/15;567.27000;567.27000
APR-16;04/01/13;F35MEDFC;APR-16;01/04/16;30/04/16;01/04/14;31/03/16;556.52000;556.52000
APR-17;04/01/13;F35MEDFC;APR-17;01/04/17;30/04/17;01/04/15;31/03/17;548.77000;548.77000
APR-13;04/01/13;BR DATED;APR-13;01/04/13;30/04/13;01/04/11;29/03/13;108.46000;108.46000
APR-14;04/01/13;BR DATED;APR-14;01/04/14;30/04/14;30/03/12;31/03/14;102.53000;102.53000
APR-15;04/01/13;BR DATED;APR-15;01/04/15;30/04/15;01/04/13;31/03/15;98.19000;98.19000
APR-16;04/01/13;BR DATED;APR-16;01/04/16;30/04/16;01/04/14;31/03/16;94.49000;94.49000
JAN-21;04/01/13;F630GCW;JAN-21;01/01/21;31/01/21;01/01/19;31/12/20;85.57000;85.57000
JUL-13;04/01/13;F630GCW;JUL-13;01/07/13;31/07/13;01/07/11;28/06/13;93.50000;93.50000
JUL-14;04/01/13;F630GCW;JUL-14;01/07/14;31/07/14;29/06/12;30/06/14;90.95000;90.95000
JUL-15;04/01/13;F630GCW;JUL-15;01/07/15;31/07/15;01/07/13;30/06/15;88.83000;88.83000
JUL-16;04/01/13;F630GCW;JUL-16;01/07/16;31/07/16;01/07/14;30/06/16;87.01000;87.01000
对于最小QT_END的每个索引,我想读取PRC_RF0。
我写过类似
的东西class GMRTest
{
public string CRVLABEL;
public string INDEX;
public string MATLABEL;
public DateTime ST_START;
public DateTime ST_END;
public DateTime QT_START;
public DateTime QT_END;
public string PRC_RF0;
public string PRC_RF1;
}
并将此方法读入列表(listData)
listData.GroupBy(s => s.INDEX).Select( aa => new {Key = aa.Key, Data = aa.OrderBy(ab => ab.ST_START) } );
然而,这仍然给我所有的数据,我想要的是最小日期(strongTART)的数据。
任何帮助都是感激的。
谢谢
尝试在OrderBy
呼叫后附加First()
。例子:
var result = listData.
GroupBy(s => s.INDEX).
Select(group => new {Key = group.Key, Data = group.
OrderBy(ab => ab.ST_START).
First()});