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

  • 相关阅读:
    python中取列表的后半部分元素
    python中列表分片
    python中统计列表中元素出现的次数
    python中range()函数用法
    pyhton中实现列表元素顺序颠倒
    python中列表元素求交集和并集
    python中编写抽奖小游戏
    python中删除列表元素
    python中列表的去重复和取重复
    欲为Java技术大牛所需的25个学习要点
  • 原文地址:https://www.cnblogs.com/firekylin/p/2023115.html
Copyright © 2011-2022 走看看