我试图从3个不同的组/桶中的Access表中收集随机的记录样本。在我的示例中,我希望每个[呼叫持续时间]存储桶中有50个随机记录,总共150条记录。我使用UNION子句加入每个组。返回的结果不是随机的,每个50个桶只是从1/2/2018的第一个调用日期中提取出来的。它就像TOP子句只是查看表中符合条件的前50条记录,但我想从整个表中获得真正的随机样本。感谢
SELECT * FROM (
SELECT TOP 50
[Workgroup],[Last Name],[First Name],[Titanium Number],
[Phone Number], [Inbound-Outbound], [Date of the Call], [Time of the Call],
[Duration of the Call], ID
FROM PCA_Calls WHERE
([Date of the Call] >= #1/1/2018# ) AND
([Date of the Call] <= #1/31/2018# ) AND
([Duration of the Call] >= 420) AND ([Duration of the Call] <=900) AND
([Workgroup] = "PCA0001A" )
UNION
SELECT TOP 50
[Workgroup],[Last Name],[First Name],[Titanium Number],
[Phone Number], [Inbound-Outbound], [Date of the Call], [Time of the Call],
[Duration of the Call], ID
FROM PCA_Calls WHERE
([Date of the Call] >= #1/1/2018# ) AND
([Date of the Call] <= #1/31/2018# ) AND
([Duration of the Call] >= 901) AND ([Duration of the Call] <=1800) AND
([Workgroup] = "PCA0001A" )
UNION
SELECT TOP 50
[Workgroup],[Last Name],[First Name],[Titanium Number],
[Phone Number], [Inbound-Outbound], [Date of the Call], [Time of the Call],
[Duration of the Call], ID
FROM PCA_Calls WHERE
([Date of the Call] >= #1/1/2018# ) AND
([Date of the Call] <= #1/31/2018# ) AND
([Duration of the Call] >= 1801) AND ([Duration of the Call] <=2700) AND
([Workgroup] = "PCA0001A" )
) AS Sub ORDER BY rnd(INT(NOW*ID)-NOW*ID);enter code here