目标
增加每个插入CATEGORYID
,直到完成。1
5
WHILE
场景
BEGIN
DECLARE MaxAnnounces INT UNSIGNED DEFAULT 5;
DECLARE Counter INT UNSIGNED DEFAULT 1;
DECLARE NewWeek INT UNSIGNED DEFAULT
(SELECT WEEKID FROM announces_empire ORDER BY WEEKID DESC LIMIT 1);
START TRANSACTION;
WHILE Counter < MaxAnnounces DO
INSERT INTO announces
(NAME, CAPTION, DESCRIPTION, IMAGEURL, LINK, CATEGORYID, WEEKID, YEARID)
VALUES
("Hello!",
"Click here.",
"Can you tell me your name?",
"example.com/img.jpg",
"google.com",
-- HERE I WANT TO INCREASE BY 1 EACH 5 INSERTS --
40,
2013);
SET Counter = Counter + 1;
END WHILE;
COMMIT;
END
问题
我不知道语法。
问题亮点
而不是-- HERE I WANT TO INCREASE BY 1 EACH 5 INSERTS --
我试图以这种方式做某事:
IF(Counter % 5, x + 1, 1),
x
我还没有定义的变量在哪里。
Guilherme,你为什么不能用这个IF
?怎么了?这样做插入的值总是1
.
谁能给我一盏灯?