SQL语句 随机取出n条记录再将这些记录插入到其他表
答案:3 悬赏:0
解决时间 2021-02-08 21:13
- 提问者网友:多余借口
- 2021-02-07 23:58
SQL语句 随机取出n条记录再将这些记录插入到其他表
最佳答案
- 二级知识专家网友:猎杀温柔
- 2021-02-08 01:10
top 10 不是随机
你用的这个数据不知道支不支持sample一类的子句?
比如
select *
from problem
sample 10
你用的这个数据不知道支不支持sample一类的子句?
比如
select *
from problem
sample 10
全部回答
- 1楼网友:為→妳鎖鈊
- 2021-02-08 02:23
把
declare @id int
select top 10 @id=id from Problem where Lv=@Lv --如何随机取10条
insert into Paper (Problemid)values(@id)
改成:
insert into Paper(Problemid) select top 10 id from Problem where Lv=@Lv order by NewID()
- 2楼网友:一池湖水
- 2021-02-08 02:03
表有多少字段,你只是插入一个随机数到一个字段吗?
declare @i int
set @i=0
while @i<10 --修改数值你要添加多少行数据
begin
insert into biao
select rand()*100
set @i=@i+1
end
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯