我正在尝试从数据库中随机选择一个条目,但只能从最近的 100 个条目中选择一个条目。有什么想法吗?谢谢。
for MySql -
SELECT * FROM
(SELECT * FROM table1 order by created_date desc LIMIT 100) table1_alias
ORDER BY RAND()
LIMIT 1
此处的内部查询获取前 100 条记录,您可能需要将created_date替换为其他内容。
外部查询是提供随机记录的内容。
对于预言机,您将需要这样的东西 -
select * from
(select * from table1 where rownum < 100 order by created_date desc) table1_alias
where rownum=1 order by dbms_random.value