SELECT( (SELECT SUM(`количество` `цена`) AS `сумма` FROM `покупка` WHERE ...) - (SELECT SUM(`количество` `цена`) AS `сумма` FROM `продажа` WHERE ...) ) AS `остаток`
CREATE TRIGGER trigger_name {BEFORE | AFTER} {INSERT | UPDATE | DELETE} ON table_name FOR EACH ROW BEGIN -- Тело триггера (заявления SQL) END;