我的 sql 表中有两个bit
类型列用于员工考勤,以及休假的类型1 for Medical Leave or 2 for Paid Leave
,其中的值就像,
FirstHalfLeave Type SecondHalfLeave Type
------------ ---- ------------- ----
0(Absent) 1 1 2
1(Present) 1 1 2
我需要将这两个字段相加以使其离开一天,并且我需要显示确切的结果,例如
Type Days
---- ------
MedicalLeave 0.5
PaidLeave 1.0
为此我尝试过
select cast(
sum(
(
CAST(StaffAttendance.FirstHalfStatus as Integer) +
CAST(StaffAttendance.SecondHalfStatus as integer)
)
/ 2.0
) as float
) as TotalLeave
,case when StaffAttendance.FirstHalfLeaveType = 2 OR
StaffAttendance.SecondHalfLeaveType=2 then 'Paid Leave'
else 'Medical Leave'
end as Status
from StaffAttendance
where MONTH(StaffAttendance.date)=MONTH(GetDate())
group by StaffAttendance.FirstHalfLeaveType,StaffAttendance.SecondHalfLeaveType
但它的分组不好,我不知道如何做到这一点,任何人都可以在这里帮助我,提前谢谢