mysql更新某一列的值


update 表1  set a=100
追問:
如果這個值 我不希望它等於100,而是希望它的是值是小於100的隨機整數,有辦法實現嗎
追答:
update 表1 set a=floor(rand()*100)

這個代表0-99的整數,不包括負數
追問:
太神奇了,真的實現了,我最后再請教高手 一個問題,如果我希望,這值是5,10,15,20,這四個數中隨機的一個數,有辦法實現嗎,拜托給予解答
追答:
select t.num from
(select 5 num
union all
select 10 num
union all
select 15 num
union all
select 20 num) t
order by rand() limit 1

 

隨機2個的話,就把limit后的數字換成2,以此類推

追問:
select t.num from(select 5 numunion allselect 10 numunion allselect 15 numunion allselect 20 num) torder by rand() limit 1 和  update 表1 set a=floor(rand()*100)  怎么組合呀,我試了老是錯誤 ,就是讓a=這四個數中的一個
追答:
update 表1 set a=
(select t.num from(select 5 num union all select 10 num union all select 15 num union all select 20 num) t order by rand() limit 1)


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM