我想从这个表中选择6条随机记录,基于2列,主题和taxonomy.The记录的选择必须是平衡的,重复的主题和分类应该保持一个minimum.Is有一个算法来做到这一点吗?
在SQL或java中的任何帮助都将预先是appreciated.Thanks。
发布于 2017-02-26 05:01:15
你可以用有序集上的第n个样本来做这件事。它类似于:
select t.*
from (select t.*, (@rn := @rn + 1) as rn
from t cross join
(select @rn := 0) params
order by topics, taxonomy
) t cross join
(select count(*) as cnt from t) tt
where rn % floor(cnt / 6) = 1;其思想是使用模块化算法将每n个值取到6,根据数据的大小,您可能需要修改where中的确切参数。
https://stackoverflow.com/questions/42464916
复制相似问题