时间:2021-07-01 10:21:17 帮助过:26人阅读
想实现如下效果,就是分组后时间最大的那一条数据:
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() };
SQL Server分组查询某最大值的整条数据(包含linq写法)
标签:inf partition 写法 int 分组查询 uid win source key