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 }); 

  • 相关阅读:
    帆软查看注册用户的数据库信息
    [已解决]报错:sql server 返回结果出现中文乱码
    消除点击单元格时出现的黑框
    python tcp udp函数装饰器,无需亲自手写socket连接代码。
    介绍一个python代码自动运行在远程机器的三方包。
    python paramiko上传文件夹到linux
    filebeat自定义索引名,filebeat索引模板
    mydumper
    mysql误删ibd文件
    mysql update多字段时引发的一个问题
  • 原文地址:https://www.cnblogs.com/firekylin/p/2023115.html
Copyright © 2011-2022 走看看