hive实例运用

参考资料:https://dblab.xmu.edu.cn/blog/1005/

1、Hive数据导入

(1)将small_user.csv文件导入到hive中

(2)根据导入数据格式特征,创建名为user的外部表

create external table if not exists myuser
(
`user_id` int,
`item_id` int,
`behaviour_type` int,
`user_geohash` string,
`item_category` string,
`time` string
)
row format delimited fields terminated by ',';

文件导入到hive中

load data local inpath '/home/hadoop/small_user.csv' overwrite into table myuser;

数据字段解释:

user_id(用户id)

item_id(商品id)

behaviour_type(包括浏览、收藏、加购物车、购买,对应取值分别是1、2、3、4)

user_geohash(用户地理位置哈希值,有些记录中没有这个字段值,可以删除此字段)

item_category(商品分类)

time(该记录产生时间)

2、Hive数据分析

(1)查询前10条数据

select * from myuser limit 10;

select behaviour_type from myuser limit 10;(指定列)

(2)查询2014年11月18日到2014年11月20日有多少人浏览了商品

select count(*) from myuser where behaviour_type='1' and `time`<'2014-11-18' and `time`>'2014-11-20';

(3)查询2014年12月12日“95qobv6”当天发出到该地点的货物的数量

select count(*) from myuser where user_geohash='95qobv6' and `time`='2014-12-12' and behaviour_type='4';

(4)查询2014年12月12日这一天在该网站浏览商品超过5次的用户id

select user_id from myuser where behaviour_type='4' and `time`='2014-12-12' group by uesr_id having count(behaviour_type='4')>5;

(5)统计2014年11月18日一天的用户行为,即分别有多少人浏览、收藏、加购物车、购买商品。

select count(*) from myuser where behaviour_type=1 and `time`='2014-11-18 02';
select count(*) from myuser where behaviour_type=2 and `time`='2014-11-18 02';
select count(*) from myuser where behaviour_type=3 and `time`='2014-11-18 02';
select count(*) from myuser where behaviour_type=4 and `time`='2014-11-18 02';
select behaviour_type, count(behaviour_type) count_tape  from myuser where `time`= '2014-11-18 02' group by behaviour_type;

(6)统计2014年12月12日商品购买率最高的5件商品

select item_id from myuser where `time`= '2014-11-18 11'and behaviour_type='4' order by behaviour_type limit 5;

  1. 统计2014年12月12日购物力最强的前10位客户

select user_id from myuser where `time`= '2014-12-12 01'and behaviour_type='4' order by behaviour_type limit 10;

(8)统计网站每个月卖出的商品的个数

(9)查询2014年12月12日所有地区用户行为分布情况


 

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值