课堂测试——HIVE 数据分析
作者:互联网
题目要求:
具体操作:
①hive路径下建表:sale
create table sale
(day_id String, sale_nbr String, buy_nbr String, cnt String, round String)
ROW format delimited fields terminated by ',' STORED AS TEXTFILE;
②导入数据:
load data local inpath '/opt/module/data/sales.csv' into table sale;
③数据清洗:
3、数据分析处理:
(1)统计每天各个机场的销售数量和销售金额。要求的输出字段 day_id,sale_nbr,,cnt,round 日期编号,卖出方代码,数量,金额。
命令:
查询语句:
select day_id,sale_nbr,sum(cnt),sum(round) from sale where sale_nbr like 'C%' group by day_id,sale_nbr;
创建表table1:
create table table1(day_id String,sale_nbr String, cnt String,round String) ROW format delimited fields terminated by ',' STORED AS TEXTFILE;
将查询语句保存至table1:
insert overwrite table table1 select day_id,sale_nbr,sum(cnt),sum(round) from sale where sale_nbr like 'C%' group by day_id,sale_nbr;
(2)统计每天各个代理商的销售数量和销售金额.要求的输出字段 day_id,sale_nbr,cnt,round 日期编号,卖出方代码,数量,金额
命令:
查询语句:
select day_id,sale_nbr,sum(cnt),sum(round) from sale where sale_nbr like 'O%' or buy_nbr like 'O%' group by day_id,sale_nbr;
创建表table2:
create table table2(day_id String,sale_nbr String, cnt String,round String) ROW format delimited fields terminated by ',' STORED AS TEXTFILE;
将查询结果保存至table2:
insert overwrite table table2 select day_id,sale_nbr,sum(cnt),sum(round) from sale where sale_nbr like 'O%' or buy_nbr like 'O%' group by day_id,sale_nbr;
(3)统计每天各个代理商的销售活跃度。 要求的输出字段 day_id,sale_nbr, sale_number 日期编号,卖出方代码,交易次数(买入或者卖出均算交易次数)
命令:
查询语句:
select day_id,sale_nbr,count(sale_nbr)from sale where sale_nbr like "O%" group by sale_nbr,day_id;
创建表table3:
create table table3(day_id String,sale_nbr String, sale_number String) ROW format delimited fields terminated by ',' STORED AS TEXTFILE;
将查询结果保存至表table3:
insert overwrite table table3 select day_id,sale_nbr,count(sale_nbr)from sale where sale_nbr like "O%" group by sale_nbr,day_id;
导入mysql:
一
1.建表(可视化建表):
2.sqoop路径下执行命令:
bin/sqoop export \
> --connect jdbc:mysql://master:3306/mysql \
> --username root \
> --password 000000 \
> --table table1\
> --num-mappers 1 \
> --export-dir /user/hive/warehouse/table1 \
> --input-fields-terminated-by ","
二
bin/sqoop export \
> --connect jdbc:mysql://master:3306/mysql \
> --username root \
> --password 000000 \
> --table table2\
> --num-mappers 1 \
> --export-dir /user/hive/warehouse/table2 \
> --input-fields-terminated-by ","
三
bin/sqoop export \
> --connect jdbc:mysql://master:3306/mysql \
> --username root \
> --password 000000 \
> --table table3\
> --num-mappers 1 \
> --export-dir /user/hive/warehouse/table3 \
> --input-fields-terminated-by ","
标签:数据分析,String,--,nbr,sale,HIVE,id,课堂,day 来源: https://www.cnblogs.com/zyj3955/p/15370389.html