gpt4 book ai didi

MySQL 从前 100 条中随机选择

转载 作者:行者123 更新时间:2023-11-29 14:26:33 25 4
gpt4 key购买 nike

我正在尝试从数据库中选择一个随机条目,但仅从最新的 100 个条目中选择。有什么想法吗?谢谢。

最佳答案

对于 MySql -

SELECT * FROM 
(SELECT * FROM table1 order by created_date desc LIMIT 100) table1_alias
ORDER BY RAND()
LIMIT 1

此处的内部查询获取前 100 条记录,您可能需要将created_date 替换为其他内容。

外部查询给出随机记录。

<小时/>

对于 Oracle,你需要这样的东西 -

select * from 
(select * from table1 where rownum < 100 order by created_date desc) table1_alias
where rownum=1 order by dbms_random.value

关于MySQL 从前 100 条中随机选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10862571/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com