hive 常用查询语句

来源:互联网 发布:java 进程看门狗 编辑:程序博客网 时间:2024/05/15 03:39

查询不相同的androidid  

select count(distinct androidid) from  table where dt='date ' and  androidid is not null and androidid <>'' 

            and androidid <> 'null' and androidid <> 'NULL' AND androidid <> '_NULL' AND androidid <> '_Null'  and  appkey <> 'appkey';    结果:4055


查询唯一用户 总数 , 因为一个用户是以四个属性为确定唯一值的 ,所以相加然后去重

 hive> select  count(distinct  concat(nvl(idfa, ''), nvl(mac, ''), nvl(imei, ''), nvl(androidid, '')) ) from  table  where dt='date'  and  appkey <> 'appkey';          结果: 23235487 

根据appkey分组,然后查询不同的idfa有多少个。

 select appkey, count(distinct lower(idfa)) from  table where dt='date' and  idfa is not null and idfa <>''  and lower(idfa) <> 'null' and lower(idfa) <> 'NULL' AND lower(idfa) <> '_null' AND lower(idfa) <> '_null_'   group by appkey ;
 


0 0