我具有以下表:多個條件
僱員終止ID員工狀態日期 1所述的NULL 2所述的NULL 3 I 2016年1月1日 4 I 2016年12月15日 5 I 2016年1月1日
我想就以下報告:
- 當前活動僱員數量 - 2
- 非活動僱員數量 - 3
- 在最後1個月終止僱員數量 - 2
這是一塊我使用的代碼:
select
case when employee_status='A' then count(employee_id) else '' end,
case when employee_status='I' then count(employee_id) else '' end,
case when employee_status='I'
then
(select count(employee_id)
from employee
where date_of_termination between '1/1/2016' and '2/1/2016')
else '' end
from employee
我的結果集爲:
Active | Inactive | Inactive_last_month
2 | 0 | 0
0 | 3 | 2
我想實現以下目標:
Active | Inactive | Inactive_last_month
2 | 3 | 2
任何建議,將不勝感激。
這工作。謝謝。 – Anonymous