SQL server 需要给一列插入随机数字,这个数字只能随机插入0或1,请问如何写

2025-02-25 00:48:59
推荐回答(4个)
回答1:

insert into 表名(列名) values(case when rand()>0.5 then 1 else 0 end)
或者
insert into 表名(列名) values(cast( floor(rand()*2) as int))

回答2:

select convert(int,RAND()+0.5)
=======================
这样就可以了。简单明了。

回答3:

cast(rand()*10 as int)%2

回答4:

rand()*10