我需要sql查询从表中获取随机项目,不包括先前以相同方式提取的项目。
答案 0 :(得分:0)
我试图以我能想到的最佳方式回答您的解决方案。然而,仍有一些不明确的问题,我没有考虑到这些问题;
当您用完之前选择的值时,您会怎么做?然后你什么都不回来?在某些时候,您已经随机选择了所有值。
- 醇>
应选择多少项目以及“之前”的具体用语
测试数据
declare @randomitem nvarchar(50)
declare @firstrun int = (select count(*) from dbo.randomlist)
if(@firstrun = 0)
BEGIN
SELECT top 1 @randomitem=[Names]
FROM [LegOgSpass].[dbo].[Randoms]
order by newid();
truncate table dbo.randomitems;
insert into dbo.randomitems
select @randomitem
;
select * from dbo.randomitems a
where not exists (select * from dbo.randomlist b where a.namesused = b.namesused);
insert into dbo.randomlist
select @randomitem;
END
if(@firstrun >= 1)
BEGIN
SELECT top 1 @randomitem=[Names]
FROM [LegOgSpass].[dbo].[Randoms] a
where not exists (select * from dbo.randomlist b where a.Names = b.namesused)
order by newid();
truncate table dbo.randomitems;
insert into dbo.randomitems
select @randomitem
;
select * from dbo.randomitems a
where not exists (select * from dbo.randomlist b where a.namesused = b.namesused);
insert into dbo.randomlist
select @randomitem;
END
SQL脚本
select * from dbo.Randoms
select * from dbo.randomitems
select * from dbo.randomlist
<强>选择强>
interface HttpProgressEvent {
type: HttpEventType.DownloadProgress | HttpEventType.UploadProgress
loaded: number
total?: number
}