我有一个包含大量记录的 MS Access 表。我想创建一个查询来随机选择 10% 的记录。但是,最小记录数应为 20。因此,如果记录总数为 180,则应忽略 10% 条件并过滤掉最少 20 条记录。
我已使用前 10% 回报设置成功检索到 10% 数据。我需要应用最少 20 条记录标准。有人可以进一步指导我吗?
必须统计记录,手动调整SQL:
Const TopCount As String = "20"
Const TopPercent As String = "10%"
Dim Sql As String
Dim TopValue As String
Dim Records As DAO.Recordset
Sql = "Select Top {0} * From YourTable"
If DCount("*", "YourTable") > 200 Then
TopValue = TopPercent
Else
TopValue = TopCount
End If
Sql = Replace(Sql, "{0}", TopValue)
Set Records = CurrentDb.OpenRecordset(Sql)