0
mySQL의 SQL 서버에서 수행 한 일부 코드를 다시 만들려고합니다. 테이블의 모든 행에 행을 삽입하고 싶습니다. 나는이 작업을 수행하는 루프를 사용하고, SQL 서버에 내가 SELECT TOP @foo하위 쿼리의 MYSQL 제한에서 변수 사용
을 사용 여기에 내가 제한 @mtop에 오류가 내 MySQL의
begin
set @maxloop = (select max(id) from `LeagueInfo`);
set @loopno = 1;
while @loopno <= @maxloop DO
SET @mtop = (select `teams` * `homegames` from `LeagueInfo` where id = @loopno);
SET @div = (select `LeagueShortName` from `LeagueInfo` where id = @loopno);
SET @teams = (select teams from `LeagueInfo` where id = @loopno);
SET @homegames = (select homegames from `LeagueInfo` where id = @loopno);
SET @fthgsum = (select sum(`FTHG`)/@teams/@homegames from `footy` where `id` in(select`id`, `div` from `footy`
where `div` = @DIV
order by `matchdate` desc LIMIT @mtop));
SET @ftagsum = (select sum(`FTAG`)/@teams/@homegames from `footy` where `id` in(select`id`, `div` from `footy`
where `div` = @DIV
order by `matchdate` desc LIMIT @mtop));
insert into `looptable` (`di`, `homeav`, `awayav`) values (@div, @fthgsum,@fthgsum);
set @loopno = @loopno +1;
END while;
END;
입니다. 나는 이것을 준비된 문장으로 둘러 볼 수는 있지만 하위 쿼리에서는 그것을 수행하는 방법을 모르겠다는 것을 읽었다. 거기에 할 일이 있었는지 아니면 내가 또 다른 테이블에있는 각 행에 대해 다른 테이블의 값을 기반으로 행 x 상위 금액을 선택할 수 있습니다.
감사 폴
코드의 회선에서
팀 및 homegames는 int이므로 @mtop을 @mtop으로 생각해야합니다. – Marshall10001
전체 "select"문은 무엇을 반환합니까, 행입니까 숫자입니까? –
은 where 절로 인해 하나의 행만 선택해야하므로 숫자입니다. – Marshall10001