hive取隨機的數(shù)據(jù)盅弛,可以使用rand()函數(shù),用rand()對數(shù)據(jù)排序挪鹏,取topN
如果要用到分組取隨機數(shù)见秽,比如每個班級隨機取10人,針對這種每個分組取topN的情況讨盒,可以使用
row_number() over(partition by fieldx order by rand()) as rn
示例:
select date,imei
from(
select date,imei,row_number() over(partition by sp_modify order by rand()) as rn
from tmp_mod ) mod
where mod.rn <= 1000