Hive汽车销售数据分析系统实战开发:

Hive汽车销售数据分析系统实战开发:

汽车销售(Atuo Sales)是消费者支出的重要组成成分,同时能很好的反映出消费者对经济前景的信心。通常,汽车销售情况我们了解一个国家经济循环强弱情况的第一手资料,早于其他个人消费数据的公布。因此,汽车销售为随后的零售额和个人消费支出提供了很好的预示作用,汽车消费额占零售额的25%和整个销售总额的8%。另外,汽车销售可作为预示经济衰退和复苏的早期信号。

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-5xiJ47Wg-1607946899632)(C:\Users\Lenovo\Pictures\Saved Pictures\1.jpg)]

第一步:
创建数据库:
create database  if not exists cars;
使用数据库:
use cars;
使用rz命名上次数据文件到虚拟机上:

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-lBocdDcY-1607946899636)(C:\Users\Lenovo\Pictures\Saved Pictures\2.jpg)]

创建表car:
create external table car(
province string comment '省',
month int comment '月',
city string comment '市',
district string comment '区县',
year int comment '年',
model string comment '车辆型号',
manufacturer string comment '制造商',
brand string comment '品牌',
vehicletype string comment '车辆类型',
ownership string comment '所有权',
nature string comment '使用性质',
quantity int comment '数量',
enginemodel string comment '发动机型号',
displacement int comment '排量',
power int comment '功率',
fuel string comment '燃料种类',
length1 int comment '车长',
width1 int comment '车宽',
height1 int comment '车高',
length2 int comment '厢长',
width2 int comment '厢宽',
height2 int comment '厢高',
numberofaxles int comment '轴数',
wheelbase int comment '轴距',
frontwheelbase int comment '前轮距',
tirespecification string comment '轮胎规格',
tirenumber int comment '轮胎数',
totalquality int comment '总质量',
completequality int comment '整备质量',
approvedquality int comment '核定载质量',
approvedpassenger string comment '核定载客',
tractionquality int comment '准牵引质量',
chassisenterprise string comment '底盘企业',
chassisbrand string comment '底盘品牌',
chassismodel string comment '底盘型号',
engineenterprise string comment '发动机企业',
vehiclename string comment '车辆名称',
age int comment '年龄',
gender string comment '性别'
)
row format delimited fields terminated by ',';

加载数据:
load data local inpath '/hivedata/car.csv' into table cars;
#load data local inpath '自己存放数据文件的地方' into table car;


如果你的数据库没有改的话会出现中文乱码问题:

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-A78rdlZj-1607946899638)(C:\Users\Lenovo\Pictures\Saved Pictures\3.jpg)]

下述连接可以解决:

另外一种方法就是:
文件如果是.csv后缀的,在window打开的话,会不是utf-8格式,你用记事本打开,
把文件改成.txt格式就可以在window下变成utf-8格式了,可以通过rz命令上传。
在hive打开用select*from查询时就不会出现乱码了。

数据分析
1.乘用车辆和商用车辆的销售数量和比例
select '非营运',sum(if(a.nature='非营运',a.cnt,0)),'营运',sum(if(a.nature!='非营运',a.cnt,0)) 
from 
(select nature,count(*) as cnt 
from cars group by nature having nature is not null and nature!='') a;
Total MapReduce CPU Time Spent: 6 seconds 810 msec
OK
非营运	66478	营运	3884
Time taken: 32.365 seconds, Fetched: 1 row(s)
2.山西省2013年每个月的汽车销售数量比例
select  month,c1.ss/c2.sum 
from 
(select month,sum(quantity) as ss 
from cars where province = '山西省' and year = '2013' group by month ) c1,
(select sum(quantity) as sum 
from cars where province = '山西省' and year = '2013') c2;
Total MapReduce CPU Time Spent: 9 seconds 150 msec
OK
1	0.14799181376311077
2	0.05831272561894204
3	0.09306159574770473
4	0.06587362496802251
5	0.0732071288479577
6	0.05547028225462608
7	0.06323015263920867
8	0.06378442909525028
9	0.06948352804070379
10	0.1044882180722549
11	0.10053722179585571
12	0.1045592791563628
Time taken: 53.486 seconds, Fetched: 12 row(s)
3.买车的男女比例和男女对车的品牌的选择
select '男性',B.man/(B.man+B.woman),'女性', B.woman/(B.man+B.woman) 
from
(select '男性',sum(if(A.gender='男性',A.cnt,0)) as man,'女性',sum(if(A.gender='女性',A.cnt,0)) as woman 
from
(select gender,count(*) as cnt
from cars where gender is not null and gender != '' group by gender) A) B;
Total MapReduce CPU Time Spent: 5 seconds 880 msec
OK
男性	0.7010659323952227	女性	0.29893406760477725
Time taken: 34.488 seconds, Fetched: 1 row(s)
select gender,brand,count(*) as cnt
from cars
where  gender is not null and gender != ''  and age is not null
group by gender,brand
having brand is not null and brand !=' '
order by cnt desc
limit 5;
Total MapReduce CPU Time Spent: 5 seconds 330 msec
OK
男性	五菱	28208
女性	五菱	12004
男性	长安	3679
男性	东风	3214
男性	五菱宏光	2331
Time taken: 33.615 seconds, Fetched: 5 row(s)
4.车的所有权,车辆型号,车辆类型
select a.cnt,count(*) 
from 
(select concat(model,ownership,vehicletype) as cnt from cars) a 
group by a.cnt;
ZK6726DX3单位大型专用校车	1
ZK6726DXA9单位大型专用校车	4
ZK6729D2单位大型普通客车	2
ZK6729DB单位大型普通客车	16
ZK6731DG1单位大型普通客车	6
ZK6731NG1单位大型普通客车	24
ZK6750D2单位大型普通客车	17
......
5.不同车型在一个月的销售量
select month,vehicletype,count(*) from cars group by vehicletype,month having month is not null and vehicletype is null and vehicletype != '';

6.不同品牌车销售情况,统计发动机和燃料种类
select brand,enginemodel,fuel,count(*) from cars group by brand,enginemodel,fuel;

7.统计五菱某一年每月的销售量

select brand,month,count(*) from cars group by brand,month having brand='五菱';
Total MapReduce CPU Time Spent: 3 seconds 940 msec
OK
五菱	1	5589
五菱	2	2226
五菱	3	3557
五菱	4	2389
五菱	5	3351
五菱	6	2302
五菱	7	2893
五菱	8	2980
五菱	9	3422
五菱	10	5278
五菱	11	4809
五菱	12	4963
Time taken: 16.416 seconds, Fetched: 12 row(s)

U Time Spent: 3 seconds 940 msec
OK
五菱 1 5589
五菱 2 2226
五菱 3 3557
五菱 4 2389
五菱 5 3351
五菱 6 2302
五菱 7 2893
五菱 8 2980
五菱 9 3422
五菱 10 5278
五菱 11 4809
五菱 12 4963
Time taken: 16.416 seconds, Fetched: 12 row(s)

我的一下查询的截图:
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述


  • 0
    点赞
  • 41
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Deng872347348

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值