将同一用户的结果合并为一个结果
Combine result of same user into one result
我尝试结合我的结果,如果“txtApplName”和“LeaveTypeDesc”相同,则总天数应添加并显示在加上“Totaldays”之后。
例如,在图像记录编号 6 和 7 中,应合并结果并添加“txtApplTotalDays”。我被困在这里了。顺便说一下,我使用的是 SQL Server 2014。
select txtApplName, type.LeaveTypeDesc, department.DeptName, txtManagerName, final.txtApplTotalDays, final.txtApplLeaveStartDate, final.txtApplLeaveEndDate
from [dbo].[EN_TBL_FINAL_FORM] final
INNER JOIN EN_TBL_MAST_DEPARTMENT department on final.lstApplDepartment = department.DeptID
INNER JOIN EN_TBL_MAST_LEAVETYPE type on final.lstApplLeaveType =type.LeaveTypeID
where final.txtApplLeaveStartDate >= 'GETDATE()-10' and final.txtApplLeaveEndDate <= 'GETDATE()'
Sample Data:
txtApplName LeaveTypeDesc DeptName txtManagerName txtApplTotalDays
Ng Hospitalization Development PH 2.0
Aqila Maternity Leave Human ELE 1.0
Sharah Annual Leave Human ELE 1.0
Sharah Annual Leave Human ELE 1.0
Aqilah Annual Leave Human ELE 1.0
Expected Data:
txtApplName LeaveTypeDesc DeptName txtManagerName txtApplTotalDays
Ng Hospitalization Development PH 2.0
Aqilah Maternity Leave Human ELE 1.0
Sharah Annual Leave Human ELE 2.0
Aqila Annual Leave Human ELE 1.0
我猜你正在寻找 GROUP BY
。对于提供的示例数据,您可以使用以下查询来实现您的预期结果。
SELECT txtApplName,LeaveTypeDesc, DeptName,txtManagerName,SUM(txtApplTotalDays)
FROM YOUR_TABLE
GROUP BY txtApplName,LeaveTypeDesc, DeptName,txtManagerName
我尝试结合我的结果,如果“txtApplName”和“LeaveTypeDesc”相同,则总天数应添加并显示在加上“Totaldays”之后。
例如,在图像记录编号 6 和 7 中,应合并结果并添加“txtApplTotalDays”。我被困在这里了。顺便说一下,我使用的是 SQL Server 2014。
select txtApplName, type.LeaveTypeDesc, department.DeptName, txtManagerName, final.txtApplTotalDays, final.txtApplLeaveStartDate, final.txtApplLeaveEndDate
from [dbo].[EN_TBL_FINAL_FORM] final
INNER JOIN EN_TBL_MAST_DEPARTMENT department on final.lstApplDepartment = department.DeptID
INNER JOIN EN_TBL_MAST_LEAVETYPE type on final.lstApplLeaveType =type.LeaveTypeID
where final.txtApplLeaveStartDate >= 'GETDATE()-10' and final.txtApplLeaveEndDate <= 'GETDATE()'
Sample Data:
txtApplName LeaveTypeDesc DeptName txtManagerName txtApplTotalDays
Ng Hospitalization Development PH 2.0
Aqila Maternity Leave Human ELE 1.0
Sharah Annual Leave Human ELE 1.0
Sharah Annual Leave Human ELE 1.0
Aqilah Annual Leave Human ELE 1.0
Expected Data:
txtApplName LeaveTypeDesc DeptName txtManagerName txtApplTotalDays
Ng Hospitalization Development PH 2.0
Aqilah Maternity Leave Human ELE 1.0
Sharah Annual Leave Human ELE 2.0
Aqila Annual Leave Human ELE 1.0
我猜你正在寻找 GROUP BY
。对于提供的示例数据,您可以使用以下查询来实现您的预期结果。
SELECT txtApplName,LeaveTypeDesc, DeptName,txtManagerName,SUM(txtApplTotalDays)
FROM YOUR_TABLE
GROUP BY txtApplName,LeaveTypeDesc, DeptName,txtManagerName