gpt4 book ai didi

mysql - 如何插入时间戳为 "X days ago"的行

转载 作者:行者123 更新时间:2023-11-29 02:28:58 25 4
gpt4 key购买 nike

我正在编写一些代码来生成用于测试鼠海豚的虚拟数据。

我希望时间戳字段在过去 90 天内。鉴于我有随机 0 < X < 90,我如何INSERT INTO table timestamp values(CURRENT_TIMESTAMP - X DAYS)? (忽略其他字段,因为我对那些没有问题)

最佳答案

使用 RAND() , 返回一个随机浮点值 v0 <= v < 1.0 范围内.使用 ABS()摆脱 float 值。

ABS(RAND() * 100)

INSERT INTO table (timestamp) values(CURRENT_TIMESTAMP - INTERVAL ABS(RAND() * 100) DAY)

SqlFiddle 演示 here

关于mysql - 如何插入时间戳为 "X days ago"的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15920691/

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