我的数据表包含一些像这样的列:
例如:
WorkHour Salary Name
60 100 A
70 120 B
65 105 C
WorkHour的总和: 195
薪资总和: 225
我希望列“WorkHour”和“Salary”的总和,但有条件: 如果Name == A将WorkHour添加到sum但不添加它的Salary。
这是我的代码:
var resultSum = from row in dt.AsEnumerable()
group row by row.Field<string>("UserId") into grp
select new
{
Salary = grp.Sum(r => r.Field<decimal>("Salary")),
WorkHour = grp.Sum(r => r.Field<decimal>("WorkHour"))
};
foreach (var rn in resultSum)
{
decimal dSalary = rn.Salary;
decimal WorkHour = rn.WorkHour;
}
答案 0 :(得分:2)
对记录进行分组,然后在计算Private Sub CommandButton1_Click()
With Me.OLEObjects("CommandButton1").Object
.Caption = IIf(.Caption = "Enable", "Disable", "Enable")
Range("E13:E14").Locked = .Caption = "Enable"
End With
End Sub
时Salary
之前添加Where
:
Sum