https://pastein.ru/t/7hv

  скопируйте уникальную ссылку для отправки


with sld as 
(select s.*, i.ui4 as ui4 from shelf_life_dc s 
 join item i on s.item = i.code),
tr1 as 
(select sld.item, sld.lot, sld.dc, max(o.shelflife_in_perc) as in_perc, max(o.shelflife_out_perc) as out_perc 
 from sld  join osg o on sld.ui4 = o.ui4 /*and sld.dc = o.dest*/
 group by sld.item, sld.lot, sld.dc)
select * from tr1 where in_perc != '0' and out_perc != '0'