码迷,mamicode.com
首页 > 其他好文 > 详细

Hive实现从表中随机抽样得到一个不重复的数据样本

时间:2019-02-25 20:23:33      阅读:275      评论:0      收藏:0      [点我收藏+]

标签:order   mit   HERE   select   hive   一个   uil   sql   between   

select a.* 
from (
select a.*,rand(12345) as random
from tripdata a
) a
where random between 0 and 0.2;

  

a.country       a.city  a.visitors      a.random
阿联酋  迪拜    268     0.3618031071604718
阿联酋  迪拜    108     0.932993485288541
澳大利亚        墨尔本  230     0.8330913489710237
澳大利亚        墨尔本  188     0.32647575623792624
澳大利亚        堪培拉  378     0.2355237906476252






select distinct a.*
from tripdata a
order by rand(12345) 
limit 5;

 

country       city  visitors
阿联酋  阿布扎比        157
阿联酋  阿布扎比        137
阿联酋  迪拜    144
阿联酋  阿布扎比        227
澳大利亚        堪培拉  240


https://www.jianshu.com/p/2b73e7c53355

Hive实现从表中随机抽样得到一个不重复的数据样本

标签:order   mit   HERE   select   hive   一个   uil   sql   between   

原文地址:https://www.cnblogs.com/Allen-rg/p/10433000.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!