select o.diametr, o.gost, (o.ves - p.ves) as itog from ostatki o left join potrebnost p on o.gost=p.gost and o.diametr = з.diametr