您应该能够使用“从组中选择 n”类型的查询,但您需要一个唯一的 ID:
SELECT
t.ID,
t.Element,
t.Section
FROM Elements AS t
WHERE t.ID In (
SELECT Top 2 ID
FROM Elements q
WHERE q.Element=t.Element
ORDER BY Rnd([id])*1000)
我已经经历过很多次了,我认为您将不得不为随机排序添加一个字段,然后在运行查询之前更新该字段。这将更新 [Competency Elements] 中名为 RandomNumber 的字段
UPDATE [Competency Elements]
SET [Competency Elements].RandomNumber = Rnd([element id])*1000;
然后百分比选择,我认为对于这个特定的数据集它必须大于 33:
SELECT Val([comp section number]) AS [Sect No],
s.[section description],
e.[element number],
e.[element description],
Rnd(e.[element id]) AS Expr1,
s.[section id],
e.[element id],
x.example,
s.[competency id],
c.[comp number],
c.[competency category]
FROM competencies AS c
INNER JOIN (([competency sections] AS s
INNER JOIN [competency elements] AS e
ON s.[section id] = e.[section id])
INNER JOIN examples AS x
ON e.[element id] = x.[element id])
ON c.[competency id] = s.[competency id]
WHERE (( ( e.[element id] ) IN (SELECT TOP 35 PERCENT [element id]
FROM [competency elements] q
WHERE q.[section id] = e.[section id]
ORDER BY randomnumber) ))
ORDER BY Val([comp section number]);
There are a number of issues around getting a random selection from a group.