10.4 第三问

(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 ","

 

 

posted @ 2022-10-04 18:09  lss1226  阅读(22)  评论(0)    收藏  举报