8,494
社区成员




Dim staffs = From p In db.Staff _
Group By p.姓名,p.部门 Into g = Group _
Select 姓名,部门,工资=g.Sum(Function(p) p.工资),奖金=g.Sum(Function(p) p.奖金)
var table = array
.GroupBy(item => new { Name = item.Name, Deprt = item.Deprt })
.Select(grouping => new
{
Name = grouping.Key.Name,
Depart = grouping.Key.Deprt,
Salary = grouping.Sum(x => x.Salary),
Bonus = grouping.Sum(x => x.Bonus)
});
var array = new Foo[]{
new Foo(){ Name="张三",Deprt="业务部", Salary=2200, Bonus=300},
new Foo(){ Name="李四",Deprt="资源部", Salary=3100, Bonus=200},
new Foo(){ Name="王五",Deprt="工 会", Salary=2800, Bonus=100},
new Foo(){ Name="赵六",Deprt="财务部", Salary=3300, Bonus=500},
new Foo(){ Name="张三",Deprt="业务部", Salary=1000, Bonus=100},
new Foo(){ Name="马七",Deprt="工程部", Salary=3300, Bonus=300},
new Foo(){ Name="王五",Deprt="工 会", Salary=1200, Bonus=300}
};
var table = from item in array
group new { Salary = item.Salary, Bonus = item.Bonus }
by new { Name = item.Name, Deprt = item.Deprt } into grouping
select new
{
Name = grouping.Key.Name,
Depart = grouping.Key.Deprt,
Salary = grouping.Sum(x=>x.Salary),
Bonus = grouping.Sum(x=>x.Bonus)
};
var staffs = from p in db.Staff
group p by new {Name=p.Name,Departments=p.Departments} into g
select new
{
Name=g.Key.Name,
Departments=g.Key.Departments,
TotalWage=g.Sum(p=>p.Wage),
TotalAward=g.Sum(p=>p.Award)
};