Hive实例-汽车销售

声明

本数据来自网络,不代表任何意义。

数据样例

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

打开集群,进入hive,根据所有字段建表。

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';

在这里插入图片描述
将数据写入表中
在这里插入图片描述

案例需求

1.统计乘用车辆和商用车辆的数量(即非营运和营运车辆)

select nature,count(nature) from cars where nature != '' group by nature;

在这里插入图片描述

2.统计山西省2013年每个月的汽车销售数量的比例

select month,round(sum_month/sum,2) as per
from (select month,count(month) as sum_month
from cars 
where month is not null
group by month) as a,
(select count(number) as sum from cars) as b;

在这里插入图片描述

3.统计买车的男女比例

select sex,round(sin/sum,2) as per
from (select sex,count(sex) as sin from cars
where sex is not null and sex != '' group by sex) as a,
(select count(sex) as sum from cars) as b;

4.统计的车的所有权、型号和类型

select owner,cartype,mold
from cars
where owner is not null
and cartype is not null
and mold is not null
and owner!=''
and cartype!=''
and mold!=''

在这里插入图片描述

5.统计不同类型车在一个月(对一段时间:如每个月或每年)的总销售量

select mold,month,count(number)
from cars
where length(mold) != 0 and month is not null
group by month,mold
order by mold,month;

在这里插入图片描述

6.通过不同类型(品牌)车销售情况,来统计发动机型号和燃料种类

select brand,mold,collect_set(concat(fuel,'  ',ftype))
from cars
where length(brand) != 0
and length(mold) != 0
and fuel!=''
and ftype!=''
group by brand,mold;

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

select brand,month,count(brand)
from cars
where month is not null
and length(brand)!=0
and brand='五菱'
group by month,brand;

在这里插入图片描述

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值