所以我需要提取符合以下条件的记录:
具有最低PayDate但也具有最高ReconciliationDate的记录。 可以看到这样的记录示例
create function test() returns setof varchar as 'select * from temp;' language sql;
因此要返回的正确记录将是#5
如何使用C#实现呢?
到目前为止,我已经拥有了:
public class Data {
public string Name { get; set; }
public DateTime PayDate { get; set; }
public DateTime ReconciliationDate { get; set; }
}
--------------------------------------------------
| Name | PayDate | ReconciliationDate |
--------------------------------------------------
| Andrew | 11/14/2018 | 07/01/2018 |
--------------------------------------------------
| Andrew | 10/14/2018 | 06/01/2018 |
--------------------------------------------------
| Andrew | 05/14/2018 | 08/01/2018 |
--------------------------------------------------
| Andrew | 05/14/2018 | 03/01/2018 |
--------------------------------------------------
| Andrew | 05/14/2018 | 10/01/2018 |
答案 0 :(得分:0)
您正在寻找LINQ方法OrderBy
和ThenBy
在您的情况下
.OrderBy(x => x.PayDate).ThenByDescending(x => x.ReconciliationDate).First