Здравствуйте, не понимаю какое добавить еще условие, чтобы решить
DELIMITER //
CREATE TRIGGER Buget_Trigger
AFTER INSERT
ON Buget5
FOR EACH ROW BEGIN
if((select MaxCount from Buget5 where (select max(dateee) where dateee<(now())) )<(select Buget from Buget5 where (select max(dateee) where dateee<(now())))) then
update Insects set Count=Count+20 where(select max(datee) where datee<(now()));
update Mammals set Count=Count+20 where(select max(datee) where datee<(now()));
update ColdBloodedness set Count=Count+20 where(select max(datee) where datee<(now()));
end if;
END //
insert into Mammals(mammals_id, id, typee, count, datee) VALUES (1,null,'',7,'2019-12-13');
insert into ColdBloodedness(ColdBloodedness_Id, id, typee,datee, count) VALUES (1,null,'','2019-12-13',10);
insert into Insects(insects_id, id, typee, count,datee) VALUES (1,null,'',5, '2019-12-13');
insert into Buget5(buget_id, id, buget, maxcount, dateee) VALUES (1, null,600, 200,'2019-12-13');
select * from Insects;
select * from ColdBloodedness;
select * from Mammals;
Но если сделаю второй раз, то ничего не сработает и будет ошибка 1242
insert into Buget5(buget_id, id, buget, maxcount, dateee) VALUES (2, null,600, 200,'2019-12-13');
select * from Insects;
select * from ColdBloodedness;
select * from Mammals;