-1

所以我找到了一篇文章,谈到将某些逻辑测试放在 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(); 
4

1 回答 1

0

您需要进行单独查询以获取最大 ID:

INT maxId;

SELECT MAX(game_id) INTO maxId
FROM games;

label1: while xGame <= maxId DO
    ...
END WHILE label1;
于 2015-07-17T23:32:25.870 回答