hive统计店铺每个月的营业额以及到当目前的历史累计额

    xiaoxiao2022-07-13  164

    --------数据 名称,月份,资金 a,01,150 a,01,200 b,01,1000 b,01,800 c,01,250 c,01,220 b,01,6000 a,02,2000 a,02,3000 b,02,1000 b,02,1500 c,02,350 c,02,280 a,03,350 a,03,250 ----建表 create table t_store( name string, months int, money int ) row format delimited fields terminated by "," 1.将数据加载进去 load data local inpath "/home/hadoop/store.txt" into table t_storre 2 需求 编写Hive的HQL语句求出每个店铺的当月销售额和累计到当月的总销售额 店铺,当月累计,累计到当前的销售 ----------- 1.求出每个店铺的当月累计消费额 创建一个临时表 create table tmp_store1 as select name,months,sum(money) as money from t_store group by name,months; select * from tmp_store1; 名称 月份 累计收益 a 01 5000 a 02 6000 b 01 400 b 02 5000 对临时表tmp_store1表中的数据进行自然连接 create table tmp_store2 as select a.name aname,a.months amonths,a.money amoney ,b.name bname,b.months bmonths,b.money bmoney from tmp_store1 a join tmp_store1 b on a.name=b,name order by anaem,amonths; select * from tmp_store2; a 01 5000 a 01 5000 a 01 5000 a 02 6000 a 02 6000 a 01 5000 a 02 6000 a 02 6000 b 01 400 b 02 5000 b 01 400 b 01 400 b 02 5000 b 01 400 b 02 5000 b 02 5000 比较统计 select aname,amonths,amoney sum (bmoney) as total from tep_store2 where amonths>=bmonths group by aname,amonths,amoney
    最新回复(0)