You really should just have one table; separate in and out tables make more problems than they solve. Guessing at some of your column names, I suspect you don't really have a column named 'Date Out' etc
select product as Product,
coalesce(sum(case when dt < '2020-12-01' then amount end),0) as BegBal,
coalesce(sum(case when dt between '2020-12-01' and '2020-12-31' and type='in' then amount end),0) as In,
coalesce(sum(case when dt between '2020-12-01' and '2020-12-31' and type='out' then -amount end),0) as Out,
coalesce(sum(case when dt <= '2020-12-31' then amount end),0) as EndBal
from (
select 'in' as type, product, date_in as dt, in as amount from in
union all
select 'out' as type, product, date_out, -amount from out
) in_out;
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…