zoukankan      html  css  js  c++  java
  • 用Linq怎么实现Row_Number排序 火麒

    select row_number()over(order by total),* from adayrate
    查询到的数据是:
    1 张三 100
    2 李四 90
    3 啊舒服 90
    4 爱是 80
    5 斯蒂芬 75
    6 士大夫 75
    7 刘德华 70
    (1)这个用Linq怎么实现?


    如果需要得到下面这样的数据,该又怎么实现啊?
    1 张三 100
    2 李四 90
    2 啊舒服 90
    4 爱是 80
    5 斯蒂芬 75
    5 士大夫 75
    7 刘德华 70
    (2)这个用Linq怎么实现?


    如果需要得到下面这样的数据,该又怎么实现啊?
    1 张三 100
    2 李四 90
    2 啊舒服 90
    3 爱是 80
    4 斯蒂芬 75
    4 士大夫 75
    5 刘德华 70
    (3)这个用Linq怎么实现?
    1.
    //参考思路  这是如何实现Row_Number的
    public List<ScoreWithRank> GetHighScoresWithRank(string gameId, int count)
    {
        Guid guid = new Guid(gameId);
        using (PPGEntities entities = new PPGEntities())
        {
            var query = from s in entities.Scores
                        where s.Game.Id == guid
                        orderby s.PlayerScore descending
                        select new
                        {
                            PlayerName = s.PlayerName,
                            PlayerScore = s.PlayerScore
                        };

            return query.AsEnumerable() // Client-side from here on
                        .Select((player, index) => new ScoreWithRank()
                                {
                                    PlayerName = player.PlayerName,
                                    PlayerScore = player.PlayerScore,
                                    Rank = index + 1;
                                }
                        .ToList();

        }
    }
    2.
    start = page * rowsPerPage;
    Products.OrderByDescending(u => u.Sales.Count())
      .Skip(start)
      .Take(rowsPerPage)
      .AsEnumerable()
      .Select((u, index) => new { Product = u, Index = index + start }); 

  • 相关阅读:
    php 下载文件
    thinkphp3.1 发送email
    微擎 plugin 时间插件 图片上传插件不显示 报错 影响下面执行
    Java中基本数据类型的对比记忆
    堆内存设置以及垃圾回收方式
    try--catch--finally中return返回值执行的顺序(区别)
    Java中的值传递和引用传递
    全面总结sizeof的用法(定义、语法、指针变量、数组、结构体、类、联合体、位域位段)
    10进制转换成16进制最简单的方法
    quartz 框架定时任务,使用spring @Scheduled注解执行定时任务
  • 原文地址:https://www.cnblogs.com/firekylin/p/2023115.html
Copyright © 2011-2022 走看看