How to Join Three table with Sum Function

20 Views Asked by At

I have three tables with Customer Name as a Primary key.

Stock Table

Receipt Table

Dispatch Table

Output

I would like to combine all three tables via Customer Name and Sum the Quantities.

Please help me to combine the third table as well.

I managed to combine a single table but unable to add the second table. My query is something like this

SELECT Stock.Customer, SUM(Stock.[Available Quantity]) AS AvailableQty, O.ShippedQty
FROM     (SELECT Storer, SUM([Shipped Quantity]) AS ShippedQty
                  FROM      Dispatch
                  GROUP BY Customer) AS O LEFT OUTER JOIN
                  Stock ON Stock.Customer= O.Customer
GROUP BY Stock.Customer, O.ShippedQty
1

There are 1 best solutions below

0
manoj On
   SELECT st.customer_name , rt.recieved_quantity, dt.dispatch_quantity
   FROM Stock_Table st
   LEFT JOIN   Receipt_Table rt
   ON st.customer_name = rt.customer_name
   LEFT JOIN Dispatch_Table dt
   ON st.customer_name = dt.customer_name