【发布时间】:2021-02-02 12:28:39
【问题描述】:
我想从一个表(1000 行)中随机选择值并将它们放入另一个表(4000 行)。
第一个表是 Customer(1000 行),第二个表是 Customer_Account(4000 行)。他们都有一个列 Customer_ID 和 Account_ID。在 Customer_Account 表中,仅填充了 Customer_ID 列。 Customer_Account 表的 Account_ID 列我想用从客户的 Account_ID 列中随机选择的值填充。这意味着来自 Customer 表的相同值可能在 Customer_Account 表中出现多次。
此查询将第一个表中随机选择的单个值放入另外 4000 次:
set CustomerID = t2.CustomerID
from Customer_Account t1
cross apply (
select top 10 CustomerID
from Customer
where CustomerID=t1.CustomerId
order by NewID()
) t2
关于如何解决这个问题的任何建议?
【问题讨论】: