title: MySQL SELECT calculation subject to stricter criteria than other SELECT fields--how?
body: <p>Previously, the following query was limited based on work_category_id.  Turns out we need information from as subclass of another work_category_id, so now I'm limiting on job_code_id instead.  Job_code_id 29 is work_category_id 88, all other job_code_ids shown are work_category_id 36.</p>
  
  <p>I need hours and performance for each of these job_code_ids, but specifically for the 'cases_per_hr' calculation, I only want to divide cases by all hours except those from job_code_id 29.  I tried a nested case when, but that didn't seem to make much sense.  Please help!</p>
  
  <pre><code>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')
  </code></pre>