;with totalcount as (select cast(count(sn) as decimal) as totalfrom completedUnit)select (100 - (cast(count(distinct sn) as decimal)/(select * from totalcount))*100) as 'yield'from productiondefect
;with totalcount as (select cast(count(sn) as decimal) as totalfrom completedUnit)select (100 - (cast(count(distinct sn) as decimal)/(select * from totalcount))*100) as 'yield'from productiondefectwhere sn = (select c.sn from completedUnit as c join productiondefect as d on c.sn = d.sn where c.operator = 'Operator')
;with totalcount as (select cast(count(sn) as decimal) as totalfrom completedUnitwhere MONTH(dateentered) = '10' and operator = 'operator')select (100 - (cast(count(distinct d.sn) as decimal)/(select * from totalcount))*100) as 'yield'from productiondefect as djoin completedUnit as c on d.sn = c.snwhere 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)
CAST( yield AS decimal( 3,1))