我无法完成这个因为我给我一个恼人的错误,我检查并检查但我仍然不知道发生了什么,这里是代码
DROP PROCEDURE IF EXISTS gen_par;
CREATE PROCEDURE gen_par()
BEGIN
DROP TABLE IF EXISTS tmpPool;
DROP TABLE IF EXISTS tmpFixture;
CREATE TEMPORARY TABLE tmpPool (
J INT NOT NULL AUTO_INCREMENT,
ID INT NOT NULL,
unpicked BIT NOT NULL DEFAULT 1
, PRIMARY KEY ( J )
);
CREATE TEMPORARY TABLE tmpFixture (
ID INT NOT NULL AUTO_INCREMENT,
HomeID INT NOT NULL,
AwayID INT NOT NULL,
GrpNum INT NOT NULL,
PRIMARY KEY ( `ID` )
);
INSERT INTO tmpPool (ID)
SELECT id
FROM equipos
ORDER BY id;
SELECT COUNT(*) INTO @NumTeams FROM tmpPool;
IF @NumTeams % 2 THEN
INSERT INTO tmpPool (ID) VALUES (0);
SET @NumTeams = @NumTeams + 1;
END IF;
ALTER TABLE tmpPool CHANGE COLUMN J J INT NOT NULL
, ADD INDEX J_foo (J ASC)
, DROP PRIMARY KEY;
SET SQL_SAFE_UPDATES = 0; -- Kill bogus warnings on updates.
SET @GroupNum = 1;
WHILE @GroupNum < @NumTeams DO
REPEAT
SELECT ID INTO @Home FROM tmpPool WHERE unpicked = 1 ORDER BY J ASC LIMIT 1;
SELECT ID INTO @Away FROM tmpPool WHERE unpicked = 1 ORDER BY J DESC LIMIT 1;
INSERT INTO tmpFixture (HomeID, AwayID, GrpNum)
VALUES (@Home, @Away, @GroupNum);
UPDATE tmpPool SET unpicked = 0 WHERE ID = @Home OR ID = @Away;
SELECT COUNT(*) INTO @TeamsLeft FROM tmpPool WHERE unpicked = 1;
UNTIL @TeamsLeft < 1
END REPEAT;
SET @GroupNum = @GroupNum + 1;
UPDATE tmpPool SET unpicked = 1;
UPDATE tmpPool SET J = J + 1 WHERE J > 1;
UPDATE tmpPool SET J = 2 WHERE J = @NumTeams + 1;
END WHILE;
INSERT INTO
partidos (eqloc, eqvis)
SELECT
IF( F.HomeID = 0, (SELECT id FROM equipos eq WHERE eq.id = F.AwayID), (SELECT id FROM equipos eq WHERE eq.id = F.HomeID) ),
IF( F.AwayID = 0 || F.HomeID = 0, 0, (SELECT id FROM equipos eq WHERE eq.id = F.AwayID) ),
FROM
tmpFixture F
ORDER BY
F.GrpNum,
1;
END;
错误是:
[Err] 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM
tmpFixture F
ORDER BY
F.GrpNum,
1;
END' at line 65
我做错了什么?
谢谢:)
答案 0 :(得分:2)
在这部分:
IF( F.AwayID = 0 || F.HomeID = 0, 0, (SELECT id FROM equipos eq WHERE eq.id = F.AwayID) ),
FROM
tmpFixture F
在FROM之前的第一行末尾有一个尾随逗号。它不应该存在。