• C# linq 实现Rank Over Partition by


    public class TData
    
        {
    
           public int Id { get; set; }
    
           public string StuName { get; set; }
    
           public string ClsName { get; set; }
    
           public decimal Score { get; set; }
    
        }
    
     
    
     
    
       public class ToolTest
    
        {
    
            [Fact]
    
           public void Test()
    
            {
    
               var list = new List<TData>
    
                {
    
                   new TData() { Id = 1, StuName = "zhangsan", ClsName = "1", Score = 70 },
    
                   new TData() { Id = 2, StuName = "lisi", ClsName = "1", Score = 80 },
    
                   new TData() { Id = 3, StuName = "wangwu", ClsName = "1", Score = 90 },
    
                   new TData() { Id = 4, StuName = "liaoliu", ClsName = "1", Score = 100 },
    
                   new TData() { Id = 5, StuName = "zhangsan", ClsName = "2", Score = 90 },
    
                   new TData() { Id = 6, StuName = "lisi", ClsName = "2", Score = 40 },
    
                   new TData() { Id = 7, StuName = "wangwu", ClsName = "2", Score = 50 },
    
                   new TData() { Id = 8, StuName = "liaoliu", ClsName = "2", Score = 60 },
    
                };
    
     
    
               //var g = list.GroupBy(g => g.ClsName);
    
     
    
               var resut1 = list.GroupBy(g => g.ClsName).Select(s => s.Select(s => s.Score).Max());
    
     
    
               var resut2 = list.GroupBy(g => g.ClsName).Select(s => s.OrderByDescending(o => o.Score).FirstOrDefault());
    
     
    
            }
    
        }
  • 相关阅读:
    CSS 去掉文字选中状态
    解决MAC系统升级导致COCOAPODS失效问题
    qr-mili Tekniskt stöd
    JavaScript 随笔
    Https 单向验证 双向验证
    git 常用指令
    h5或者微信端吊起app
    创建本地服务器环境
    jenkins 关闭和重启的实现
    jenkins 忘记用户名和密码
  • 原文地址:https://www.cnblogs.com/hofmann/p/16640158.html
Copyright © 2020-2023  润新知