想实现如下效果,就是分组后时间最大的那一条数据:
1、SQL
SELECT * FROM ( SELECT * , ROW_NUMBER() OVER ( PARTITION BY RIP_GUID ORDER BY RU_CreatedTime DESC ) rn FROM RIP_FlowInfo ) t WHERE t.rn <= 1;
2、LINQ
var groupQuery = from t in query group t by t.RIP_Guid into g select new { key = g.Key, source = g.OrderByDescending(tt => tt.RU_CreatedTime).FirstOrDefault() };