同表複製數據,讓其日期增長sql
代碼實現markdown
DELIMITER $
DROP PROCEDURE IF EXISTS changeDate$ CREATE PROCEDURE changeDate (IN multiple int) BEGIN DECLARE i int DEFAULT 1;
DECLARE _space int DEFAULT 1;
DECLARE _sum int DEFAULT 1;
SELECT COUNT(1) INTO _space FROM (SELECT te.st_date FROM A te GROUP BY te.st_date) temp;
SELECT COUNT(*) INTO _sum FROM A te;
IF multiple > 0 THEN
WHILE i <= multiple DO INSERT INTO A ( st_date ) SELECT DATE_ADD(st_date, INTERVAL _space * i DAY) AS st_date, FROM A LIMIT 0, _sum;
SET i := i + 1;
END WHILE;
END IF;
END$ DELIMITER ;