数据表查询:最大值和分组

时间:2013-11-11 07:17:07

标签: c# ado.net datatable

我有一个数据表,如下所示:

enter image description here

根据这些内容,我需要根据statecountyidsource列获得sourcenickname的最大值。

结果应为:

enter image description here

1 个答案:

答案 0 :(得分:0)

尝试以下代码:

var result =
    from row in tbl.AsEnumerable()
    group row by new 
    {sourceKey = row["source"],sourcenicknamekey = row["sourcenickname"]} into g  
    select new
    { 
        maxSCIds = g.Max(x => x["statecountyid"])
    };