我有一张桌子
EmpAttendance
Date EmpId Attendance
1/1/12 Emp1 P
1/1/12 Emp2 P
2/1/12 Emp1 P
2/1/12 Emp2 A
由此,我想要一份报告,显示所有员工的总体呈现和缺席
AttendanceReport
EmpId Presents Absents
Emp1 2 0
Emp2 1 1
请帮帮我
答案 0 :(得分:1)
按empid
分组并使用案例仅总结礼物和缺席
select empid,
sum(case when attendance = 'P' then 1 end) as presents,
sum(case when attendance = 'A' then 1 end) as absents
from EmpAttendance
group by empid