我试图弄清楚如何在T-SQL中将我所知道的作为一个组和聚合过程来做。
我有一个List<T>
,在这个列表中,每个示例有2条记录。我需要价值较低的记录。
所以在申请中我有学生记录。所以我的列表应该是这样的:
0 studentid 1 score 75.345
1 studentid 1 score 33.653
2 studentid 2 score 94.876
3 studentid 2 score 15.234
etc....
我在List<Student>
结果中有这些记录:
var result = abc.Find<Student>...snip
需要明确的是,业务规则要求找出两者之间的较低分数。
那么我如何在Linq中完成这种过滤和选择呢?我看到有Group和Aggregate Linq扩展,但老实说,我不确定这是否是我们要追求的路线。
2条答案
按热度按时间3hvapo4f1#
使用
GroupBy
和Min
函数。axkjgtzd2#
也许这会有所帮助:
首先,你需要
order by
分数,然后group-by
名称,然后从每个组中取first
。dotnetfiddle