Я знаю, что мои знания меньше, но здесь я хочу уменьшить число в SQL и добавить его в новую строку? - PullRequest
0 голосов
/ 17 апреля 2020

Фактический результат пришел здесь ниже

enter image description here

Обязательный Требуемый результат здесь ниже

enter image description here

    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

...