On a final - just to cover all bases... if the items are not unique in the first table and thus you need to aggregate multiple rows simultaneously:

=SUMPRODUCT(($A$2:$A$4=$A8)*$B$2:INDEX($B$4:$E$4,$B$7))