hive实例-乘用车辆和商用车辆销售数据分析
数据源地址:http://pan.baidu.com/s/1cKsrKi
1.准备数据源
打开 上牌数--商用车销量数据样例.xlsx,另存为car.txt文件,打开car.txt,设置编码格式为UTF-8,保存并上传至master节点。
2.创建car 数据库,建立car表,并上传数据
create external table cars(
province string, --省份
month int, --月
city string, --市
county string, --区县
year int, --年
cartype string,--车辆型号
productor string,--制造商
brand string, --品牌
mold string,--车辆类型
owner string,--所有权
nature string, --使用性质
number int,--数量
ftype string,--发动机型号
outv int,--排量
power double, --功率
fuel string,--燃料种类
length int,--车长
width int,--车宽
height int,--车高
xlength int,--厢长
xwidth int,--厢宽
xheight int,--厢高
count int,--轴数
base int,--轴距
front int,--前轮距
norm string,--轮胎规格
tnumber int,--轮胎数
total int,--总质量
curb int,--整备质量
hcurb int,--核定载质量
passenger string,--核定载客
zhcurb int,--准牵引质量
business string,--底盘企业
dtype string,--底盘品牌
fmold string,--底盘型号
fbusiness string,--发动机企业
name string,--车辆名称
age int,--年龄
sex string --性别
)
row format delimited
fields terminated by '\t'
location '/cars';
province string, --省份
month int, --月
city string, --市
county string, --区县
year int, --年
cartype string,--车辆型号
productor string,--制造商
brand string, --品牌
mold string,--车辆类型
owner string,--所有权
nature string, --使用性质
number int,--数量
ftype string,--发动机型号
outv int,--排量
power double, --功率
fuel string,--燃料种类
length int,--车长
width int,--车宽
height int,--车高
xlength int,--厢长
xwidth int,--厢宽
xheight int,--厢高
count int,--轴数
base int,--轴距
front int,--前轮距
norm string,--轮胎规格
tnumber int,--轮胎数
total int,--总质量
curb int,--整备质量
hcurb int,--核定载质量
passenger string,--核定载客
zhcurb int,--准牵引质量
business string,--底盘企业
dtype string,--底盘品牌
fmold string,--底盘型号
fbusiness string,--发动机企业
name string,--车辆名称
age int,--年龄
sex string --性别
)
row format delimited
fields terminated by '\t'
location '/cars';
使用以下命令为cars表导入数据,并查看导入是否成功:
hive> load data local inpath 'car.txt' into table cars;
Loading data to table car.cars
Table car.cars stats: [numFiles=0, totalSize=0]
OK
Time taken: 1.244 seconds
hive> select * from cars limit 2;
OK
山西省 3 朔州市 朔城区 2013 LZW6450PF 上汽通用五菱汽车股份有限公司 五菱 小型普通客车 个人 非营运 1 L3C 8424 79.0 汽油 4490 1615 1900 NULL NULL NULL 2 3050 1386 175/70R14LT 4 2110 1275 NULL 7 NULL 上汽通用五菱汽车股份有限公司 客车 1913 男性
山西省 3 晋城市 城区 2013 EQ6450PF1 东风小康汽车有限公司 东风 小型普通客车 个人 非营运 1 DK13-06 1587 74.0 汽油 4500 1680 1960 NULL NULL NULL 2 3050 1435 185R14LT 6PR 4 1970 1290 NULL 7 NULL 东风小康汽车有限公司 EQ6440KMF重庆渝安淮海动力有限公司 客车 1929 男性
Time taken: 0.178 seconds, Fetched: 2 row(s)
3.、 汽车行业市场分析:
3.1、 通过统计车辆不同用途的数量分布
Loading data to table car.cars
Table car.cars stats: [numFiles=0, totalSize=0]
OK
Time taken: 1.244 seconds
hive> select * from cars limit 2;
OK
山西省 3 朔州市 朔城区 2013 LZW6450PF 上汽通用五菱汽车股份有限公司 五菱 小型普通客车 个人 非营运 1 L3C 8424 79.0 汽油 4490 1615 1900 NULL NULL NULL 2 3050 1386 175/70R14LT 4 2110 1275 NULL 7 NULL 上汽通用五菱汽车股份有限公司 客车 1913 男性
山西省 3 晋城市 城区 2013 EQ6450PF1 东风小康汽车有限公司 东风 小型普通客车 个人 非营运 1 DK13-06 1587 74.0 汽油 4500 1680 1960 NULL NULL NULL 2 3050 1435 185R14LT 6PR 4 1970 1290 NULL 7 NULL 东风小康汽车有限公司 EQ6440KMF重庆渝安淮海动力有限公司 客车 1929 男性
Time taken: 0.178 seconds, Fetched: 2 row(s)
3.、 汽车行业市场分析:
3.1、 通过统计车辆不同用途的数量分布
select nature,count(number) from cars where nature!='' group by nature;
3.2、 统计山西省 2013 年每个月的汽车销售数量的比例
select month,round(summon/sumcount,2)as per
from (select month,count(number) as summon from cars where
month is not null group by month) as a,
(select count(number) as sumcount from cars) as b;
3.3、 统计山西省
2013 年各市、 区县的汽车销售的分布
select city,county,count(number)as number from caars group bu sity,county;
4. 用户数据市场分析:
4.1统计买车的男女比例
select sex,round((sumsex/sumcount),2) as sexper from
select sex,round((sumsex/sumcount),2) as sexper from
(select sex,count(number) as sumsex from cars where sex!=''
group by sex) as a,
(select count(number) as sumcount from cars where sex !='') as b;
4.2、 统计的车的所有权、 车辆类型和品牌的分布
select ower,mold,brand,count(number) as number from cars
group by ower,mold,brand;
5.不同车型销售统计分析:
5.1、 统计不同品牌的车在每个月的销售量分布
5.1、 统计不同品牌的车在每个月的销售量分布
select brand,month,count(number) from cars where brand !='' and month != '' group by brand,month;
5.2、 通过不同类型(品牌) 车销售情况, 来统计发动机型号和燃料种类
select brand,mold,collect_set(ftype),collect_set(fuel) from cars where brand is not null and brand != '' and mold is not null and mold != '' group by brand,mold;