Hive(一)基础补充

数值类型可以进行加减乘除
select rank+1 from sogou limit 10;
给rank平方
pow()
select pow(rank,2) from sogou limit 10;
模(取余)
pmod()
select pmod(rank,2) from sogou limit 10;
强制类型转换
cast() 注意:cast()只是改变了查询时的数据类型,原表中列的数据类型并没有改变。
select cast(time as bigint) from sogou limit 10;
select cast(rank as string) from sogou limit 10;


将String类型的值链接起来 concat()
select concat(uid,keyword) from sogou limit 10;
字符串的长度 length()
select keyword,length(keyword) from sogou limit 10;
表的嵌套
select
sum(if(s.cnt=1,1,0)),
sum(if(s.cnt=2,1,0)),
sum(if(s.cnt=3,1,0)),
sum(if(s.cnt>3,1,0)) from 
(select uid,count(*) as cnt from sogou group by uid) s;
统计rank <=3 && order >1的用户个数:
select count(distinct s.uid) from 
(select * from sogou where rank<=3 and order >1) s;


where过滤
like的使用
查询url中以http开头进行查询的数量
select count(*) from sogou where url like 'http%' limit 10;


group by 分组查询
(一个字段)
select rank,count(*) as cnt from sogou group by rank limit 50;
(多个字段)
select rank,order,count(*) as cnt from sogou
group by rank,order;


having 需要在group by的基础上进行操作
select rank,order,count(*) as cnt from sogou
group by rank,order having cnt >3;


排序 order by   asc升序(default)  desc降序
select rank,order,count(*) as cnt from sogou
group by rank,order having cnt >3 order by cnt desc;


UNION ALL 合并数据集
查询sogou与sogou_201608两张表中rank <10 的用户个数


select count(distinct s.uid) from 
(select * from sogou where rank <10 
 union all
select * from sogou_201608 where rank <10) s;


查询sogou与sogou_201608两张表中所有的条数
select count(*) from 
(select * from sogou 
union all 
select * from sogou_201608)s;
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值