今天学了几个去重,真真是厉害死了。
sql语句
select * from tc_allusers where id in (select min(student_Id) from to_screen where organization_id="5ZAhr6r4mziutumsfX4L6m" group by student_id);
lambda表达式
var userid = screen.GetAll().Where(s => s.Organization_id == OrganizationID && s.Check_State == 0).GroupBy(s => s.Student_Id);
var res = userid.Select(x => new
{
b = x.Min(s => s.Student_Id),
}).ToList();
var allStudnetInformation = (from uid in res
join alu in ntx.Tc_Allusers on uid.b equals alu.Id
select new Tc_AllusersDTO
{
User_Name = alu.User_Name,
Id = alu.Id
});
return allStudnetInformation.ToList();
//去重,计算个数
num = getnum.GroupBy(g => g.Student_Id).Count();