Hi i was able to figure this out after i did some research all night and into the early morning. i used subqueries and unions to pull this off. this is the code i made
SELECT Z_ID, Z.Name, Z.Name2, cast(Z.UnitPrice as numeric(13,2)) as UnitPrice, abs(SUM(IL)) AS Qty, cast(UnitPrice * abs(SUM(IL)) as numeric(13,2)) as TotalAmount
FROM
(
SELECT A1.Z_ID, sum(A1.QTY) as IL
FROM A1
GROUP BY A1.Z_ID
UNION
SELECT B1.Z_ID, sum(B1.QTY) as PL
FROM B1
GROUP BY B1.Z_ID
union
SELECT B2.Z_ID, sum(B2.QTY) * -1 as SL
FROM B2
GROUP BY B2.Z_ID
union
SELECT A1.Z_ID, SUM(A1.QTY)as ISL
FROM A1
GROUP BY A1.Z_ID
) MergedTable, Z
WHERE MergedTable.Z_ID = Z.ID
GROUP BY Z_ID, Z.Name, Z.Name2, Z.UnitPrice
thank you everyone who helped! Thank you as well Prerak Patel for the useful link! I'll keep this in my toolbox for later use.