如果是MYSQL中两列不同的ELSE STATEMENT

时间:2016-11-02 12:01:15

标签: mysql

我有3个表:badge_master,match_result_updation和team_badges。

badge_master是主表,我手动将数据插入到Excel中。在match_result_updation我有一些列if sum(goal_column1) - sum(goal_column2) = 10,然后值column1将获得徽章,它将插入team_badges表中。我通过触发器处理它但在一段时间后无法继续。

match_result_updation

我试过的触发器:

CREATE TRIGGER `afterinsert_teamgoals` AFTER INSERT ON `match_result_updation` FOR EACH ROW   

BEGIN  


DECLARE goalCount1 INT(10);  
DECLARE goalCount2 INT(10);  
DECLARE badgeId BIGINT(20);  
DECLARE teamId bigint(20) default 0 ;  


SELECT team1_goal INTO goalCount1 FROM match_result_updation WHERE team1_id = NEW.team1_id  ;  

SELECT team2_goal INTO goalCount2 FROM match_result_updation WHERE team2_id = NEW.team2_id ;  

IF (goalCount1 - goalCount2 >= 10)  

Then  
Insert into team_badges(team_id,badge_id,match_id,timestamp) 
    SELECT  teamId , badgeId , match_id FROM match_result_updation limit 1;   


END IF;  

请协助。

0 个答案:

没有答案