create trigger tapp_trigger after update on business FOR EACH ROW begin set @count = (select count(*) from temp where business_id = old.id); set @Differ = (SELECT sum(TIMESTAMPDIFF(minute , create_time, modify_time)) from business where id = old.id ); if @count = 0 then insert into temp(business_id, start_time, differ) values(old.id, old.create_time, @Differ); elseif @count > 0 THEN update temp set differ=@Differ where business_id = old.id; end if; end;