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
IF
是我尚未定义的变量。
Guilherme,为什么你不能使用这个1
?会发生什么?这样插入的值始终为{{1}}。
有人可以给我一个灯吗?
答案 0 :(得分:1)
在你开始的时候,在开始的时候可能是这样吗?
IF Counter % 5
BEGIN
X = X + 1
END
并在插入中使用此变量。别忘了申报X.
答案 1 :(得分:1)
将使用以下工作:
CAST((Counter / 5) AS UNSIGNED)
OR
FLOOR(Counter / 5)
OR
FORMAT((Counter / 5),0)
它看起来像下面这样:
VALUES
("Hello!",
"Click here.",
"Can you tell me your name?",
"example.com/img.jpg",
"google.com",
CAST((Counter / 5) AS UNSIGNED),
40,
2013);