Hive数据分析实战

简介: 有以下几张数据表,请写出Hive SQL语句,实现以下需求。注:分区字段为dt,代表日期。

有以下几张数据表,请写出Hive SQL语句,实现以下需求。


注:分区字段为dt,代表日期。


1、某次经营活动中,商家发起了"异性拼团购",试着针对某个地区的用户进行推广,找出匹配用户。


参考实现:选出城市在北京,性别为男的10个用户名


select user_name
from user_info
where city=‘beijing’ and sex=‘male’
limit 10;


2、某天,发现食物类的商品卖的很好,你能找出几个资深吃货吗?

参考实现:选出在2019年6月18日,购买的商品类是food的用户名、购买数量、支付金额,并按照购买数量、支付金额倒序排序,取前10个用户。


select user_name, piece, pay_amount
from user_trade
where dt=‘2019-06-18’ and goods_category=‘food’
order by pay_amount desc, piece desc
limit 10;


3、试着对本公司2019年第一季度商品的热度与价值度进行分析。

参考实现:2019年1月到3月,每个品类有多少人购买,累计金额是多少。


select goods_category,
count(distinct user_name) as user_num,
sum(pay_amount) as total_amount
from user_trade
where dt between ‘2019-01-01’ and ‘2019-03-31’
group by goods_category;


4、2019年4月,支付金额超过5万元的用户,给VIP用户赠送优惠劵。


参考实现:2019年4月份,统计每位用户的支付金额,筛选出超过5万元的。


select user_name,
sum(pay_amount) as total_amount
from user_trade
where dt between ‘2019-04-01’ and ‘2019-04-30’
group by user_name
having sum(pay_amount)>50000;


5、去年的劳动节新用户推广活动价值分析,即拉新分析。


参考实现:统计2019年5月1日之后,每日激活用户的数量。


select sum(user_name) as user_num,
datediff(to_date(firstactivetime), ‘2019-05-01’)
from user_info
where to_date(firstactivetime) between ‘2019-05-01’ and ‘2019-05-31’
group by to_date(firstactivetime);


6、对用户的年龄段进行分析,观察分布情况。


参考实现:统计以下四个年龄段:20岁以下、20-30岁、30-40岁、40岁以上的用户数。


select case when age<20 then ‘20岁以下’
when age>=20 and age<30 then ‘20-30岁’
when age>=30 and age<40 then ‘30-40岁’
else ‘40岁以上’ end as age_type
count(distinct user_name) as user_num
from user_info
group by case when age<20 then ‘20岁以下’
when age>=20 and age<30 then ‘20-30岁’
when age>=30 and age<40 then ‘30-40岁’
else ‘40岁以上’ end;


7、去年王思聪的微博抽奖活动引起争议,我们想要观察用户等级随性别的分布情况。


参考实现:统计每个性别用户等级高低分布情况(level大于5为高级)


select sex.
if(level>5, ‘高’, ‘低’) as level_type,
count(distinct user_name) as user_num
from user_info
group by sex,
if(level>5, ‘高’, ‘低’);


8、分析每个月的拉新情况,可以倒推回运营效果。


参考实现:统计每个月激活用户的数量


select substr(firstactivetime, 1, 7) as active_month,
count(distinct user_name) as user_num
from user_info
group by substr(firstactivetime, 1, 7);


9、找出不同手机品牌的用户分布情况。


参考实现:按照手机品牌分组,统计每个品牌的用户数量。


select extra2[‘phonebrand’] as phone_brand,
count(distinct user_name) as user_num
from user_info
group by extra2[‘phonebrand’];


10、找出在2018年具有VIP潜质的用户,发送VIP试用劵。


参考实现:2018年购买的商品品类在五个以上的用户


select user_name,
count(distinct goods_category) as category_num
from user_trade
where year(dt)=‘2018’
group by user_name
having count(distinct goods_category)>5;


11、激活天数距今超过300天的男女分布情况

select sex,
count(distinct user_name) as user_num
from user_info
where datediff(current_date(),to_date(firstactivetime))>300
group by sex;


12、不同性别、教育程度的分布情况

select sex,
extra2[“education”] as education,
count(distinct user_name) as user_num
from user_info
group by sex,
extra2[“education”];


13、2019年1月1日到2019年4月30日,每个时段的不同品类购买金额分布。


select substr(from_unixtime(pay_time, ‘yyyy-MM-dd HH’), 12),
goods_category,
sum(pay_amount) as total_amount
from user_trade
where dt between ‘2019-01-01’ and ‘2019-04-30’
group by
substr(from_unixtime(pay_time, ‘yyyy-MM-dd HH’), 12),
目录
相关文章
|
1月前
|
自然语言处理 小程序 数据挖掘
数据分析实战-Python实现博客评论数据的情感分析
数据分析实战-Python实现博客评论数据的情感分析
104 0
|
2月前
|
数据采集 存储 数据挖掘
Python 爬虫实战之爬拼多多商品并做数据分析
Python爬虫可以用来抓取拼多多商品数据,并对这些数据进行数据分析。以下是一个简单的示例,演示如何使用Python爬取拼多多商品数据并进行数据分析。
|
4月前
|
SQL 数据采集 数据挖掘
大数据行业应用之Hive数据分析航班线路相关的各项指标
大数据行业应用之Hive数据分析航班线路相关的各项指标
99 1
|
4月前
|
机器学习/深度学习 算法 数据挖掘
数据分析入门系列教程-K-Means实战
数据分析入门系列教程-K-Means实战
|
4月前
|
数据采集 算法 数据可视化
数据分析入门系列教程-决策树实战
数据分析入门系列教程-决策树实战
|
8天前
|
供应链 搜索推荐 数据挖掘
Pandas实战案例:电商数据分析的实践与挑战
【4月更文挑战第16天】本文通过一个电商数据分析案例展示了Pandas在处理销售数据、用户行为分析及商品销售趋势预测中的应用。在数据准备与清洗阶段,Pandas用于处理缺失值、重复值。接着,通过用户购买行为和商品销售趋势分析,构建用户画像并预测销售趋势。实践中遇到的大数据量和数据多样性挑战,通过分布式计算和数据标准化解决。未来将继续深入研究Pandas与其他先进技术的结合,提升决策支持能力。
|
8天前
|
存储 数据可视化 数据挖掘
实战案例:Pandas在金融数据分析中的应用
【4月更文挑战第16天】本文通过实例展示了Pandas在金融数据分析中的应用。案例中,一家投资机构使用Pandas加载、清洗股票历史价格数据,删除无关列并重命名,将日期设为索引。接着,数据被可视化以观察价格走势,进行基本统计分析了解价格分布,以及计算移动平均线来平滑波动。Pandas的便捷功能在金融数据分析中体现出高效率和实用性。
|
2月前
|
数据采集 存储 数据挖掘
Python 爬虫实战之爬拼多多商品并做数据分析
在上面的代码中,我们使用pandas库创建DataFrame存储商品数据,并计算平均价格和平均销量。最后,我们将计算结果打印出来。此外,我们还可以使用pandas库提供的其他函数和方法来进行更复杂的数据分析和处理。 需要注意的是,爬取拼多多商品数据需要遵守拼多多的使用协议和规定,避免过度请求和滥用数据。
|
3月前
|
SQL 数据挖掘 数据库
SQL数据分析实战:从导入到高级查询的完整指南
SQL数据分析实战:从导入到高级查询的完整指南
61 0
|
3月前
|
SQL 数据可视化 数据挖掘
将Sqoop与Hive集成无缝的数据分析
将Sqoop与Hive集成无缝的数据分析

热门文章

最新文章