Фактический результат пришел здесь ниже
Обязательный Требуемый результат здесь ниже
select *,
case when row_number()over
(PARTITION by trgtp.size,trgtp.thickness order by trgtp.size,trgtp.thickness,trgtp.mill asc)=1
then (select isnull(sum(cod.tpcs),0) from CustomerOrder_Details as cod where
cod.psize=trgtp.size and cod.pthick=trgtp.thickness
) else
0
end as orderedpcs
,(select isnull(sum(cod.tpcs),0) from CustomerOrder_Details as cod where
cod.psize=trgtp.size and cod.pthick=trgtp.thickness
)/trgtp.pcs as [shifts]
from production_trgt_pcs as trgtp
where trgtp.size='76.1'
and ((select isnull(sum(cod.tpcs),0) from CustomerOrder_Details as cod where
cod.psize=trgtp.size and cod.pthick=trgtp.thickness
)/trgtp.pcs)>0
здесь запрос sql