【发布时间】:2018-04-02 09:40:18
【问题描述】:
我有以下两个查询,我有两个连接。
SELECT count(staff_id) FROM employee_kras as e WHERE appraisal_type_id is null
union all
SELECT count(staff_id) from employee_kras as e
where Team_KRA_Status='approved' AND Appraisal_status IS NULL
union all
SELECT count(staff_id) from employee_kras as e where appraisal_status='not submitted' and
Appraisal_Type_ID IS NOT NULL
union all
SELECT count(staff_id) from employee_kras as e where
Appraisal_status='submitted' AND Mgr_Rating_id is null
使用以下查询:
SELECT staff_id,
CASE WHEN appraisal_status='not submitted' and Appraisal_Type_ID IS NOT NULL
THEN 'Inprogress'
WHEN Appraisal_status='submitted' AND Mgr_Rating_id is null
THEN 'submitted'
WHEN Team_KRA_Status='approved' AND Appraisal_status IS NULL
THEN 'approved'
WHEN appraisal_type_id is null then 'not started'
ELSE 'submitted' END AS appraisal_status
from employee_kras ORDER BY staff_id;
【问题讨论】:
-
您的预期输出是什么?这些查询正在做不同的事情。第一个输出聚合计数,第二个输出同一张表中的所有记录。
标签: mysql