且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从SQL Server表中选择唯一的随机行,但总是复制

更新时间:2023-02-05 17:09:48

随着小到你可以将表使用这样的:

With a table as small as yours you can use something like:

INSERT INTO f_TWinGet
SELECT TOP 1 j.Char, j.Serv, j.Random
FROM dbo.just j 
LEFT JOIN f_TWinGet f
ON f.Char = j.Char
AND j.Serv = f.Serv
AND j.Random = f.Random
WHERE f.Char IS NULL
ORDER BY NEWID()

这样,确保你试图插入值不在决赛桌。

This way making sure that the values you're trying to insert is not on the final table.