LINQ Group and Count with a Max -


can write linq query following please

given data below need following player highest score each week , count of them if win more 1 week. if tie results top score in week each player gets count of one. example data includes situation

week   player         points  1      steve            35  1      mark             29  1      john             26  2      john             23  2      mark             21  2      steve            21  3      mark             42  3      john             42  3      steve            19  4      pete             28  4      john             16  4      steve            14  4      mark             12  

the result be

player         count steve            1 john             2 mark             1 pete             1 

i break 2 steps - won't mean gets executed earlier, it's simpler understand.

// each week, yield sequence of winning results var winningresultsbyweek = result in results                            group result result.week week                            let winningscore = week.max(x => x.points)                            select week.where(x => x.points == winningscore)  var winsperplayer = winningresults in winningresultsbyweek                     winningresult in winningresults                     group winningresult winningresult.player winsbyplayer                     select new { player = winsbyplayer.key,                                  count = winsbyplayer.count() }; 

the naming important here - spelling things out i've made reasonably clear. i'm sure there other ways of doing of course, that's clearest 1 i've thought of.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -