以前,以下查询受限于 work_category_id。事实证明,我们需要来自另一个 work_category_id 的子类的信息,所以现在我限制了 job_code_id。Job_code_id 29 是 work_category_id 88,显示的所有其他 job_code_id 是 work_category_id 36。
我需要每个job_code_ids的小时数和性能,但特别是对于'cases_per_hr'计算,我只想将cases除以job_code_id 29之外的所有小时数。我尝试了一个嵌套的case,但这似乎没有很有意义。请帮忙!
SELECT
d.user_id as 'employee_ID',
round((sum(d.goal_hours)/sum(d.worked_hours)),2)*100 as 'performance',
round(sum(d.goal_hours),2) as 'goal_hrs',
round(sum(d.worked_hours),2) as 'hrs_worked',
sum(d.cases) as 'total_cases_slctd',
round(sum(d.cases)/sum(d.worked_hours),0) as 'cases_per_hr',
d.metric_dt
FROM
roster r,
prod_detail d
WHERE
d.process_level = r.process_level
and d.accounting_unit = r.accounting_unit
and d.job_code_id in ('29','322','304','303','302','305','181')
-- and d.work_category_id in('36')