You can use SUMIF within SUMPRODUCT
If all the tables you describe start at A1 in the relevant sheets, with headers in row 1 and data from row 2 to row 100 then you can use this formula in sheet3 B2 copied across and down
=SUMPRODUCT(--(sheet2!$A$2:$A$100=$A2),SUMIF(sheet1!$A$2:$A$100,sheet2!$B$2:$B$100,sheet1!B$2:B$100))