SQL-group by

SELECT ActivityTemplateID FROM ActivityScene GROUP BY ActivityTemplateID ORDER BY ActivityTemplateID DESC

order by 是需要放到group by 后面的,否则会报错

MVC中linq语句获取的时候,排序也是需要放到group by之后,才有效的。

List<Model> updateList = 
dbContext.Models.GroupBy(u=>u.ActivityPackageOrderID)
.Select(u=>u.OrderByDescending(v=>v.ID).FirstOrDefault()).ToList();
原文地址:https://www.cnblogs.com/danlis/p/6272894.html