如何將兩行合併到單行中?如何根據SQL Server 2008中的條件添加2行的總和
現在這是什麼我得到...
LeaveTypeId LeaveTypeFName day
---------------------------------------
1 Casual Leave 9.0
3 SickLeave 3.0
10 Festival 4.0
11 LOP 15.0
14 National Holiday 4.0
18 P-SickLeave 1.0
19 P-Casual Leave 3.0
但我預計產量
LeaveTypeId LeaveTypeFName day
--------------------------------------------
1 Casual Leave(All) 12.0
3 SickLeave(All) 4.0
10 Festival 4.0
11 LOP 15.0
14 National Holiday 4.0
這是我的SQL查詢
select
b.LeaveTypeId,LeaveTypeFName,
SUM(case when LeaveStatus = 'FullDay'
then DATEDIFF(day, FromDate, ToDate) + 1
else 0.5
end) as 'day'
from
LeaveEntries a
join
LeaveTypes b on a.LeaveTypeId = b.LeaveTypeId
where
EmployeeId = '3862'
group by
LeaveTypeFName, b.LeaveTypeId
這是我LeaveEntries表
LeaveEntryId LeaveTypeId LeaveStatus EmployeeId FromDate ToDate
19 3 FullDay 3484 2013-02-06 2013-02-09
21 1 HalfDay 3484 2013-03-07 2013-03-07
您最好顯示錶架構和示例數據。 – dario