MSSQL 如何生成权重随机数
如果我想生成(1,2,3,4,5) 之间的随机数,但希望分别对应的权重是(10%,20%,30%,30%,10%),不知如何处理
[解决办法]
declare @num int
select @num=abs(checksum(newid()))%99+1
select case when @num between 1 and 10 then 1
when @num between 11 and 30 then 2
when @num between 31 and 60 then 3
when @num between 61 and 90 then 4
when @num between 91 and 100 then 5
end