Ok. I got the below to run. The formula returns weekly defects / overall production totals. I want to calculate weekly defect / weekly production. Is this possible?
;with totalcount as (
select
cast(count(sn) as decimal) as total
from completedUnit
where MONTH(dateentered) = '10' and operator = 'operator'
)
select
(100 - (cast(count(distinct d.sn) as decimal)/(select * from totalcount))*100) as 'yield'
from productiondefect as d
join completedUnit as c on d.sn = c.sn
where MONTH(c.dateentered) = '10' and c.operator = 'operator'
GROUP BY DATEADD(wk, DATEDIFF(wk, 7, c.dateentered), 7)
ORDER BY DATEADD(wk, DATEDIFF(wk, 7, c.dateentered), 7)