如何从表格中选择随机行?这些表很大,从表中获取随机行的有效方法是什么。有什么建议么?

http://ghtorrent.org/mysql.html

 ssh -L 3306:web.ghtorrent.org:3306 ghtorrent@web.ghtorrent.org

 on the other terminal 2
 mysql -u ght -h 127.0.0.1 ghtorrent
 select * from commits order by rand() limit 100000;

最佳答案

您可以通过执行以下操作来抽取大约1%的样本:

select *
from commits
where rand() < 0.01;


这将需要读取整个表,但是只需要读取一次即可。

这可能是获取随机样本的最佳方法。还有其他方法可以获取单个随机行或获取任意样本。

09-25 17:50