抽取随即人员——SqlServer_Proc_Random
生活随笔
收集整理的這篇文章主要介紹了
抽取随即人员——SqlServer_Proc_Random
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
--1000次內(nèi),看循環(huán)多少次@num為100,@num在1到100之間
declare @i int--計(jì)時(shí)器
declare @num varchar(3000)--行數(shù)
declare @tableLength int --長(zhǎng)度
set @tableLength = 1000
set @i = 1
while @i<=@tableLength
begin
--floor為0到100-1之間
--ceiling為1到100之間
--select @num='第'+convert(varchar(3000),@i) +'次:'+ convert(varchar(3000),cast(ceiling(rand()*100) as int))
select @num= convert(varchar(3000),cast(ceiling(rand()*100) as int))
print '第'+convert(varchar(3000),@i)+'次:'
print @num
if(@num = '100')
break;
set @i+=1
end--循環(huán)次數(shù)無(wú)限制,循環(huán)多少次后@num=表的長(zhǎng)度
declare @i int--計(jì)時(shí)器
declare @num varchar(3000)--行數(shù)
declare @tableLength int --長(zhǎng)度
select @tableLength=count(*) from PB_Messages
--print @tableLength
set @i = 1
while 1<2
begin
--floor為0到100-1之間
--ceiling為1到100之間
--select @num='第'+convert(varchar(3000),@i) +'次:'+ convert(varchar(3000),cast(ceiling(rand()*100) as int))
select @num= convert(varchar(3000),cast(ceiling(rand()* @tableLength ) as int))
print '第'+convert(varchar(3000),@i)+'次:'
print @num
if(@num = convert(varchar(3000),@tableLength))
break;
set @i+=1
end--select ROUND(15.258, 2)--DECLARE @Result INT
--DECLARE @Upper INT
--DECLARE @Lower INT
--SET @Lower = 1
--SET @Upper = 10
--SELECT @Result = ROUND(((@Upper - @Lower -1) * RAND() + @Lower), 0)
--SELECT @Resultselect * from(
select *,number = row_number() over(order by Id desc) from PB_Messages)
m where number = 2
?
轉(zhuǎn)載于:https://www.cnblogs.com/Alphonso/p/9014765.html
總結(jié)
以上是生活随笔為你收集整理的抽取随即人员——SqlServer_Proc_Random的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 为何腾讯元宝要关注青少年用户?
- 下一篇: CentOS7 配置ISCSI targ