My knowledge of SQL programming is the beginner level. This above formula, we made a friend. Everything works great when one table. I'd like to do the same function works with another table. I tried to make two stored procedures, but could not manage to run both procedures in triggers. Thanks for your answers. Best regards Joseph.

Here's the whole formula, so if you could just explain how to connect with the formula product_rac table that should have - amount.

DELIMITER $$

DROP PROCEDURE IF EXISTS lunasoft.kalkulacija$$

CREATE DEFINER=root@localhost PROCEDURE kalkulacija()

BEGIN

update aos_products_cstm as t1

set t1.kolicina=COALESCE( (select sum(t2.product_pri) from aos_products_quotes as t2 where t2.product_id=t1.id_c and t2.deleted=0 and pro_usluga_c='proizvod' group by t2.product_id),0);

* These connect with the rest of the formula

set t1.kolicina=COALESCE( -(select sum(t2.product_rac) from aos_products_quotes as t2 where t2.product_id=t1.id_c and t2.deleted=0 and pro_usluga_c='proizvod' group by t2.product_id),0);

* These connect with the rest of the formula

END$$

DELIMITER ;

DELIMITER $$

DROP TRIGGER /!50032 IF EXISTS / lunasoft.racun_unos$$

CREATE /!50017 DEFINER = 'root'@'localhost' / TRIGGER racun_unos AFTER INSERT ON aos_products_quotes FOR EACH ROW BEGIN call kalkulacija; END; $$

DELIMITER ;

DELIMITER $$

DROP TRIGGER /!50032 IF EXISTS / lunasoft.racun_izmjena$$

CREATE /!50017 DEFINER = 'root'@'localhost' / TRIGGER racun_izmjena AFTER UPDATE ON aos_products_quotes FOR EACH ROW BEGIN call kalkulacija; END; $$

DELIMITER ;

DELIMITER $$

DROP TRIGGER /!50032 IF EXISTS / lunasoft.racun_brisanje$$

CREATE /!50017 DEFINER = 'root'@'localhost' / TRIGGER racun_brisanje AFTER DELETE ON aos_products_quotes FOR EACH ROW BEGIN call kalkulacija; END; $$

DELIMITER ;