以下是我已经尝试过的在Sql中选择随机问题的方法:
select top 10 id from testTable order by newid()
- 未针对大数据进行优化
select top 10 id from testTable table sample(1 percent) - But with table sample we cannot be sure that it will always return data as it works on probability of picking pages
I have tried several other ways as taking the mod of row numbers but i still want more optimised solution
我只想要那些之前没有选择的 ID。 我不想使用 not in,因为 sql 不会缓存 not in query。
欢迎任何比在查询中使用 not 来选择尚未选择的 ID 更优化的方法。
我将讨论表的架构:
假设有如下表格:
- 存放问题的表,QuestionsTable
- 保存所有用户进行测试的表说 testUserTale
- 包含测试中每个用户的问题的表格。
所以我必须确保尝试过一次问题的学生在下一次测试中不应该再次出现
最佳答案
随机程序
此过程生成一个随机数(但请参阅使用说明)。
语法
DBMS_RANDOM.RANDOM 返回二进制整数;
编译指示
PRAGMA restrict_references(随机,WNDS) 返回值
关于sql - 选择尚未从数据库中选择的随机 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12391181/