从MS Access表中选择随机记录



我正在尝试从3个不同的组/存储桶中从访问表中收集随机的记录样本。在我的示例中,我希望从每个[呼叫的持续时间]存储桶中的50个随机记录,总共有150个记录。我加入每个小组的联合条款。返回的结果不是随机的,每个桶的50桶仅从2018年1月2日的呼叫的第一次日期开始就被拉动。就像顶级子句只是查看符合条件的前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

删除外部随机排序并将其应用于每个查询。

另外,请修改表达式以排序如下所示:

随机排序查询访问

最新更新