gpt4 book ai didi

c# - LINQ to SQL 分组依据与 take

转载 作者:行者123 更新时间:2023-11-30 15:10:04 25 4
gpt4 key购买 nike

我有一个看起来像这样的表:

Id GroupId Value

它有大约 100 行

如何在没有重复 GroupId 的情况下返回前 10 行的值?

最佳答案

应该这样做:

var results = table
.GroupBy(x => x.GroupId)
.Select(x => new { Row = x, Value = x.Max(y => y.Value) })
.OrderByDescending(x => x.Value)
.Select(x => x.Row)
.Take(10);

编辑:修改后返回整个对象。

关于c# - LINQ to SQL 分组依据与 take,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3632433/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com