gpt4 book ai didi

mysql - 在两个日期之间随机更新mysql日期

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

如何在 phpmyadmin SQL 框中更新格式为 1980 年 1 月 13 日的日期字段,其中包含 2 个日期之间的随机日期,例如 1990 年 1 月 1 日到 1995 年 1 月 1 日之间的任何一天?

我在 stackoverflow 和其他地方读到了很多答案,但没有任何对我有用。

最佳答案

您只需将日期算术与rand()一起使用即可:

select date_add(date('1990-01-01'),
interval cast(rand() * datediff('1995-01-01', '1990-01-01') as int) day)

编辑:

对于更新,本质上是相同的逻辑:

update t
set col2 = date_add(date('1990-01-01'),
interval cast(rand() * datediff('1995-01-01', '1990-01-01') as int) day)
where col = 'abc';

关于mysql - 在两个日期之间随机更新mysql日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35235670/

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