Linq distinct & max

前端 未结 4 913
猫巷女王i
猫巷女王i 2021-01-04 11:50

I have to query this table:

symbol    time
------    ----------
aaa       2013-04-18 09:10:28.000    
bbb       2013-04-18 09:10:27.000    
aaa       2013-04         


        
4条回答
  •  说谎
    说谎 (楼主)
    2021-01-04 12:09

    try out this

    var q = MyTable.GroupBy(x => x.symbol )
                   .Select(g => g.OrderByDescending(i => i.time).First());
    

    or use max like this

     var data = from r in MyTable
                       group r by r.symbol into g
                       select new { name= g.Key, data= g.Max(a=>a.time) };
    

提交回复
热议问题