таблица 1
workid est_amt amount_spent
1 1000 50
2 200 100
таблица 2
workid totalDeduction amt_payble
1 30 20
1 30 20
2 25 30
код
select count(a.workid),a.est_amt,SUM(a.amt_spent + b.total_deductions + b.amt_payable) from table1 a left join table2 b on a.workid = b.workid
результат должен быть
total_works amount_paid balance_amount_to_pay
2 305 695
получаю этот результат
total_works amount_paid balance_amount_to_pay
3 305 695