order by rand()
select * from table_name order by rand() limit 10;
使用排序函数和rand() 函数来完成随机抽样,limit限制抽样返回的数据
tablesample()
分桶抽样:tablesample (bucket x out of y on colname)
select * from table_name tablesample(bucket 1 out of 100 on rand())
随机分成100桶,抽取其中的第1桶
比例抽样:ablesample(n percent)
按照百分比抽取:select * from table_name ablesample(0.01 percent)
按大小抽取:select * from table_name ablesample(1m)
抽取指定行数:select *from table_name tablesample(20 rows)