-- Place your SQL code here ALTER TABLE `vn`.`worker` ADD COLUMN `balance` DECIMAL(10,2) NULL AFTER `businessFk`; UPDATE `vn`.`worker` w JOIN(SELECT workerFk, SUM(i.debe) - SUM(i.haber) balance FROM postgresql.income_employee i GROUP BY i.workerFk) sub ON sub.workerFk = w.id SET w.balance = sub.balance;