如何使用多列对数据进行分组 [英] How do I group data using multiple columns
本文介绍了如何使用多列对数据进行分组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我无法对从数据库中检索到的数据进行分组,该数据由于具有我不需要的数据的列而具有重复。我试图使用distinct或group by来摆脱裁员。
I am having trouble grouping a data retrieved from database which has duplication due to a column with data i don't need. i was trying to use distinct or group by to get rid of the redundancies.
var students= db.student.Distinct().Where(c => c.classdate== tomorrow || c.classdate== todayd).ToList();
它将返回学生的姓名,但也会根据当天的课程重复学生记录。我只想获得今天和明天上课的学生名单。
我尝试过的事情:
我累了
it will return student's name but also duplicates student record according to course available on that day. I just wanted to get list of students who has class today and tomorrow.
What I have tried:
I have tired
students.GroupBy(x => new { x.Fn ame, x.classdate});
推荐答案
试试这个:
Try this:
var students= db.student
.Where(c => c.classdate== tomorrow || c.classdate== todayd)
.Select(c.studentname)
.Distinct()
.ToList();
这篇关于如何使用多列对数据进行分组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文