Implementing RANK OVER SQL Clause in C# LINQ

我的未来我决定 提交于 2019-11-27 23:16:58
Adam Mills

If you don't need the exact Rank semantics (i.e. tied ranks). You can use the index available with select projections

var rank = data.GroupBy(d => d.CategoryKey)
               .SelectMany(g => g.OrderByDescending(y => y.Rate * @BAES_RATE)              
                                 .Select((x,i) => new{g.Key, Item=x, Rank=i+1}))

Otherwise you can look at this answer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!