如何在 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/