I want to write this query in laravel,
My table structures are
- product table
Product_Id int(10)
Product_Name varchar(100)
Product_Description varchar(300)
Category_ID int(11)
Brand_ID int(11)
2.Stock_IN
stock_ID int(10)
Product_ID int(11)
Product_Count int(11)
Order_No int(11)
Supplier_ID int(11)
Order_date text
- stock_out
stock_out_id int(10)
Product_ID int(11)
Product_Count int(11)
Requisition_No int(11)
Requisition_By varchar(100)
Recipient varchar(100)
My Query:
SELECT X.Product_ID,X.Product_Name,X.Count_StockIN,IFNULL(Y.Count_StockOut,0) Count_StockOut,(X.Count_StockIN-IFNULL(Y.Count_StockOut,0)) Balance FROM ( SELECT M.product_ID,M.Product_Name, SUM(Product_Count) AS Count_StockIN from (SELECT A.*,B.Product_Name FROM `stock_in` A, `products` B where A.Product_ID=B.Product_ID )M group by Product_ID,Product_Name ) X LEFT JOIN ( SELECT product_ID, SUM(Product_Count) AS Count_StockOUT from `stock_Out`group by Product_ID ) Y On X.Product_ID=Y.Product_ID
The Output is:
How to write this query in laravel 4.2 . Please help me.
