在两个日期之间随机更新mysql日期
如何在phpmyadmin SQL框中更新格式为13-01-1980且随机日期介于2个日期之间的日期字段,例如1990年1月1日至1995年1月1日之间的任何一天在两个日期之间随机更新mysql日期,mysql,date,random,Mysql,Date,Random,如何在phpmyadmin SQL框中更新格式为13-01-1980且随机日期介于2个日期之间的日期字段,例如1990年1月1日至1995年1月1日之间的任何一天 我在stackoverflow和其他网站上读到了很多答案,但对我来说没有任何效果 您只需将日期算术与rand()一起使用即可。: 编辑: 对于更新,其逻辑基本相同: update t set col2 = date_add(date('1990-01-01'), interval cast(ra
我在stackoverflow和其他网站上读到了很多答案,但对我来说没有任何效果 您只需将日期算术与
rand()一起使用即可。
:
编辑:
对于更新
,其逻辑基本相同:
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';
非常感谢你,戈登。如何在updatetablemysql命令的语法中使用它?e、 g.更新表格,其中col=“abc”set col2=“选择日期添加(日期('1990-01-01'),间隔时间(rand()*datediff('1995-01-01','1990-01-01')为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';