简体   繁体   English

选择带有嵌套查询的随机数据?

[英]select random data with a nested query?

I have a database table with quite large data. 我有一个包含大量数据的数据库表。 Now i want to get random 4 out of it. 现在我想从中随机抽取4个。 What i need is a query that fetches 1000 records from it and then selects random 4 out of these 1000 and gives it as a result. 我需要的是一个从中获取1000条记录的查询,然后从这1000条记录中随机选择4条并作为结果。 I think it can be done by nested query but have no idea how to do it. 我认为可以通过嵌套查询来完成,但不知道如何执行。 Please help me with some example code. 请帮我一些示例代码。

select * from 
(
  select * from your_table
  where some_conditions
  limit 1000
) 
as some_aliases
order by rand()
limit 4;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM