I'm trying to find out max/min/avg of process length/number of steps of each recipe and number of wafers using the recipes. The table is large and is recorded by time unit, so there are lots of repeated data such as recipe or recipe_step. Here is my code, pls help me out:
select distinct
recipe as recipe_id,
max(pl) as max_process_length,
min(pl) as min_process_length,
avg(pl) as avg_process_length,
max(steps) as max_number_of_steps,
min(steps) as min_number_of_steps,
avg(steps) as avg_number_of_steps,
count(wfr_id) as number_of_wafers
into outfile 'C:/ProgramData/MySQL/MySQL Server 8.0/Uploads/process_id.xls'
from 01m02train
group by recipe
having (
max(pl) = (
select max(pt)
from (
select count(time) as pt
from 01m02train
group by (recipe,wfr_id)
)
) as `maxpl`
and min(pl) = (
select min(pt)
from (
select count(time) as pt
from 01m02train
group by (recipe,wfr_id)
)
) as `minpl`
and avg(pl) = (
select avg(pt)
from (
select count(time) as pt
from 01m02train
group by (recipe,wfr_id)
)
) as `avgpl`
and max(steps) = (
select max(rs)
from (
select distinct count(recipe_step) as rs
from 01m02train
group by (recipe,wfr_id)
)
) as `maxrs`
and min(steps) = (
select min(rs)
from (
select distinct count(recipe_step) as rs
from 01m02train
group by (recipe,wfr_id)
)
) as `minrs`
and avg(steps) = (
select avg(rs)
from (
select distinct count(recipe_step) as rs
from 01m02train
group by (recipe,wfr_id)
)
) as `avgrs`
);