I think you should write a stored procedure for that like this:
CREATE PROCEDURE FILLSP()
BEGIN
DECLARE counter INT DEFAULT 0;
DECLARE count INT;
DECLARE repeat INT;
DECLARE pid INT;
DECLARE i INT;
SELECT COUNT(*) FROM Purchases INTO count;
WHILE counter < count DO
SELECT Stations FROM Purchases LIMIT counter,1 INTO repeat;
SELECT Purchase_id FROM Purchases LIMIT counter,1 INTO pid;
SET i = 0;
WHILE i < repeat DO
INSERT INTO allItems VALUES (pid, 17);
SET i = i + 1;
END WHILE;
SET counter = counter + 1;
END WHILE;
END
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…