salix/db/versions/.archive/10330-pinkCataractarum/00-firstScript.sql

9 lines
307 B
MySQL
Raw Permalink Normal View History

-- 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;