gpt4 book ai didi

MYSQL:为每行添加一分钟的时间戳

转载 作者:行者123 更新时间:2023-11-29 18:47:00 25 4
gpt4 key购买 nike

在“时间戳”列(表:rand_numbers”)中,每一行都有相同的时间戳:
2016-09-26 00:00:13
2016-09-26 00:00:13
2016-09-26 00:00:13
2016-09-26 00:00:13

我想在每行添加 1 分钟,结果是:
2016-09-26 00:00:13
2016-09-26 00:01:13
2016-09-26 00:02:13
2016-09-26 00:03:13

这不起作用:

CREATE PROCEDURE myproc()
BEGIN
DECLARE i int DEFAULT 1;
WHILE i <= 10 DO
INSERT INTO rand_numbers (timestamp)
VALUES ('2016-09-26 00:00:13' + INTERVAL 1 MINUTE);
SET i = i + 1;
END WHILE;
END

enter image description here

最佳答案

只需使用循环插入即可

DELIMITER //
CREATE PROCEDURE myproc()
BEGIN
DECLARE count INT DEFAULT 0;
DECLARE max INT DEFAULT 10;

WHILE(count < max) DO
INSERT INTO rand_numbers (timestamp) VALUES ('2016-09-26 00:00:13' + INTERVAL count MINUTE);
SET count = count + 1;
END WHILE;
END//
DELIMITER ;

要使用 run call myproc();

关于MYSQL:为每行添加一分钟的时间戳,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44548524/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com