I have 3 table in database 1.Warehouse, 2.Product, 3. Stock and i want to fetch the Data from these three Table like.
Frirst Column are the Warehouses names want be the header of available Quantity left in Stock.
Second Column is The Product Names which can not be duplicated.
Third Column is Available Quantity in Stock which have to convert as row along with First Column warehouse names.
output
Warehouse Name | Product Name | Available Quantity
Warehouse 1 | Shampoo | 50
Warehouse 2 | Shampoo | 100
Warehouse 3 | Shampoo | 40
Warehouse 1 | Soup | 50
Warehouse 2 | Soup | 80
Warehouse 3 | Soup | 120
I want expected Output
Product Name | Warehouse1 Qty | Warehouse2 Qty | Warehouse3 Qty | Total
Shamoo | 50 | 100 | 40 | 190
Soup | 40 | 80 | 120 | 240
What I have tried:
SELECT WareHouse.WareHouse_Name,
Product.Cat_Name 'Product Name',
SUM(Stock.Stock_In-Stock.Stock_Out) 'Available Quantity'
FROM Stock INNER JOIN
Product_Catagory ON Stock.Cat_Id = Product_Catagory.Cat_ID INNER JOIN
WareHouse ON Stock.Warehouse_ID = WareHouse.WareHouse_ID
GROUP BY Product_Catagory.Cat_Name,WareHouse.WareHouse_Name