sql
SELECT * FROM (select ROW_NUMBER()over(partition by Id order by CollTime desc) AS newIndex,* from Table) as T where T.newIndex=1
结果:
lambda
var query = _repository.GetAll().GroupBy(r => r.Id).Select(p => p.OrderByDescending(r => r.CollTime).FirstOrDefault());
Linq
from c in _repository.GetAll() group c by c.Id into g select g.OrderByDescending(r => r.CollTime).FirstOrDefault()
标签:FirstOrDefault,CollTime,newIndex,Linq,分组,select,Id,后取 From: https://www.cnblogs.com/sugarwxx/p/17402349.html