mysql插入隨機日期 mysql插入隨機日期

2021-10-19 19:31:42 字數 552 閱讀 4198

20150510  給表中插入隨機日期add_time(int) ,2014間隨機日期,最好每個月都有

由於儲存的是時間戳格式,乙個月相差2678400,一天相差86400

用到的函式

select unix_timestamp(『20141231『)  #1419955200

select from_unixtime(1391675501,『%y%m%d %h:%i:%s『)

select floor(1 + (rand() * 12))  #隨機月份

select floor(1 + (rand() * 31))  #隨機天數

selectfloor(1 + (rand() * 86400)

update `hhy_store_copy` set add_time= (select 1419955200-(floor(1 + (rand() * 12))*2678400)-(floor(1 + (rand() * 31))*86400)-floor(1 + (rand() * 86400))) where add_time is null

原文:

mysql 隨機生成日期 隨機生成指定範圍的日期

在mssql中,有些商品會偽造一些評價,但是評價資訊可能會集中在一天或幾天內,現在需要把日期打散,平均分不到乙個日期段內,那麼這段 就有用了。無 declare evid int,pid int declare evaluate cursor for select evaluateid,produc...

mysql 儲存過程按日期迴圈插入

參考部落格 定義與使用變數時需要注意以下幾點 1 declare語句必須用在degin end語句塊中,並且必須出現在degin end語句塊的最前面,即出現在其他語句之前。2 declare定義的變數的作用範圍僅限於declare語句所在的degin end塊內及巢狀在該塊內的其他degin en...

Mysq篇 了解Mysql(一)

in關鍵字和exists關鍵字select from a where a.idin select id from b 對外表a使用索引效率高,建議a為大表。select from a whereexists select from b where a.id b.id 對內表b使用索引效率高,建議b為...