以前,基于work_category_id限制了以下查询。事实证明我们需要来自另一个work_category_id的子类的信息,所以现在我限制了job_code_id。 Job_code_id 29是work_category_id 88,显示的所有其他job_code_ids都是work_category_id 36。
我需要每个job_code_ids的小时和性能,但特别是对于'cases_per_hr'计算,我只想除了来自job_code_id 29之外的所有小时除以案例。我试过一个嵌套的情况,但是没有似乎很有意义。请帮忙!
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')
答案 0 :(得分:0)
如果您只想从cases_per_hr计算中排除job_code_id ='29',则可以执行以下操作。它确实使用CASE WHEN。
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(CASE WHEN d.job_code_id <> '29' THEN d.cases ELSE 0 END)
/
sum(CASE WHEN d.job_code_id <> '29' THEN d.worked_hours ELSE 0 END)
,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')