tbl_Company_Payment *************************************************************** Sl_NO Date Company_Name Payment 1 2021-06-15 Godrej 55000 2 2021-06-15 Emami 50000 4 2021-06-15 Hemas 65000 5 2021-06-15 Emami 500 6 2021-06-18 Godrej 2500 tbl_purChase ****************************************************************** Sl_NO Company_Name Product_Name Purchase_Rate Qty value Date 1 Godrej fik 625ml 300.00 25 7500.00 2021-06-11 2 Godrej Fik 800ml 350.00 20 7000.00 2021-06-11 3 Godrej Fik 400ml 200.00 20 4000.00 2021-06-11 4 Emami Nro 200 ml 170.00 10 1700.00 2021-06-11 5 Emami Nro 100 ml 85.00 12 1020.00 2021-06-11 6 Emami Nro 50ml 56.00 14 784.00 2021-06-11 7 Hemas kumarika 400ml 255.00 25 6375.00 2021-06-11 8 Hemas kumarika 300ml 245.00 20 4900.00 2021-06-11 9 Hemas kumarika 200ml 145.00 40 5800.00 2021-06-11 result ************************************************************************************* Date Company_Name Purchase payment Remaining_Blance 2021-06-15 Hemas 0.00 65000 65000.00 2021-06-11 Hemas 17075.00 0 -17075.00 But My expected Redult like below(Note: Payment-Purchase=The remaining amount) **************************************** Date Company_Name Purchase payment Remaining_Blance 2021-06-15 Hemas 0.00 65000 65000.00 2021-06-11 Hemas 17075.00 0 47925.00 What I have tried: <pre>select f.Date,f.Company_Name,f.Purchase,f.Payment,Remaining_Blance=f.Payment-f.Purchase from (select date,Company_Name,sum(Payment)as Payment, 0 as Purchase from tbl_Company_Payment group by date,Company_Name union all select Date,Company_Name,0 as Payment,sum(value)as Purchase from tbl_purChase group by date,Company_Name)f where f.Company_Name='hemas'
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)