-- dynamic sql doesn't work in store procedure or trigger. drop trigger if exists item_review_bd_after_insert; DELIMITER // create trigger item_review_bd_after_insert after insert on pro_item_review_bd for each row begin if new.score = 1 then update pro_item_revpro set score1_cnt=score1_cnt+1 where item_id = new.item_id and revindex_id = new.revindex_id; elseif new.score = 2 then update pro_item_revpro set score2_cnt=score2_cnt+1 where item_id = new.item_id and revindex_id = new.revindex_id; elseif new.score = 3 then update pro_item_revpro set score3_cnt=score3_cnt+1 where item_id = new.item_id and revindex_id = new.revindex_id; end if; end // DELIMITER ;