调用存储函数时出现错误1111

时间:2015-07-17 23:14:23

标签: mysql mysql-error-1111

所以我发现了一篇帖子,谈到将某些逻辑测试置于HAVING而不是WHERE之后。我错过了什么仍在绊倒错误1111?

DROP PROCEDURE IF EXISTS ELO;

DELIMITER //

CREATE PROCEDURE ELO()
BEGIN

-- declares...

label1: WHILE xGame <= max(games.game_id) DO 
    SELECT games.game_id, games.game_type, games.date, games.home_team, games.away_team, games.runs0, games.runs1 
        FROM games
        WHERE games.game_id = xGame 
        HAVING (games.game_type = 0 OR games.game_type = 3)
        INTO @id, @ty, @d, @home, @away, @homeR, @awayR;

    SET startHomeELO = (SELECT team_elo.team_id, team_elo.date, team_elo.elo FROM team_elo WHERE team_id = home HAVING min(d - team_elo.date));
    SET startAwayELO = (SELECT team_elo.team_id, team_elo.date, team_elo.elo FROM team_elo WHERE team_id = away HAVING min(d - team_elo.date));

    SET eloDiff = abs((startHomeELO + 25) - startAwayELO);

    SET homeELO = (startHomeELO + (40*power(runDiff, (1/3)) * (homeWin - (1/(power(10, (eloDiff/400)) + 1)))));
    SET awayELO = (startAwayELO + (40*power(runDiff, (1/3)) * (awayWin - (1/(power(10, (eloDiff/400)) + 1)))));

    INSERT INTO team_elo (team_id, game_id, date, elo) VALUES (home, id, d, homeELO);
    INSERT INTO team_elo (team_id, game_id, date, elo) VALUES (away, id, d, awayELO);

    SET xGame = xGame + 1; 

END WHILE label1;
END; //

CALL ELO(); 

1 个答案:

答案 0 :(得分:0)

您需要执行单独的查询才能获得最大ID:

INT maxId;

SELECT MAX(game_id) INTO maxId
FROM games;

label1: while xGame <= maxId DO
    ...
END WHILE label1;