MySQL Stored procedure says alias is undefined in select statement -
i have following statement, produces error. apparently alias "r" in first line of select statement not declared, it's right there @ end of statement. have ideas?
#1327 - undeclared variable: r
create procedure `get_series_completion`(in team1_id int, in team2_id int, in round_shortname varchar(5)) begin declare num_games_total, num_games_played int; select count(*) num_games_played, r.games_per_series num_games_total ( select game_id team_games team_id in (team1_id, team2_id) group game_id having count(*) = 2 , sum(standing = 0) = 0 ) s, rounds r on r.round_shortname = round_shortname; select num_games_played/num_games_total; end$$
you should select columns before clause, query should be:
select count(*), r.games_per_series num_games_played, num_games_total ( select game_id team_games team_id in (team1_id, team2_id) group game_id having count(*) = 2 , sum(standing = 0) = 0 ) s left outer join rounds r on r.round_shortname = round_shortname;
or
select count(*), r.games_per_series num_games_played, num_games_total ( select game_id team_games team_id in (team1_id, team2_id) group game_id having count(*) = 2 , sum(standing = 0) = 0 ) s, rounds r r.round_shortname(+) = round_shortname; -- implicit left outer join
Comments
Post a Comment