我有一张基本上看起来像的表:
chandty 244 4/10/2015 32 2 3
chandty 245 4/12/2015 32 9 10
couside 247 10/29/2014 24 4 14
couside 248 10/31/2014 24 6 16
我正在尝试在名称为chandty的每一行上执行一个操作,然后每行都有一个couside,在列表中。我创建了一个包含该列的所有不同值的表,现在我正在尝试使用它来遍历表,但似乎无法使语法正确。我究竟做错了什么?我最初是在phpMyAdmin中尝试这个。这是代码:
CREATE PROCEDURE leagueavgs()
BEGIN
WHILE EXISTS (SELECT * FROM `playername`)
BEGIN
SET @tempname = (SELECT `PlayerNames`
FROM `playername`
ORDER BY `PlayerNames` ASC
LIMIT 1)
INSERT INTO `2015 average stats` (`Player Name`, `PTS`, `3PT`, `FG%`, `FT%`,`FTA`, `REB`, `AST`, `STL`, `BLK`, `TOV`)
SELECT `Player Name`, AVG(`PTS`), AVG(`3PT`), AVG(`FGM`)/AVG(FGA), AVG(FTM)/AVG(`FTA`), AVG(`FTA`), AVG(`REB`), AVG(`AST`), AVG(`STL`), AVG(`BLK`), AVG(`TOV`)
FROM `2015 gamelogs` WHERE `Player Name` = @tempname
DELETE `playername`
WHERE PlayerNames = @tempname