1. 程式人生 > 實用技巧 >大資料實戰(五十九):電商數倉(四十二)之系統業務資料倉庫(十五)商品每日銷量排行Top10

大資料實戰(五十九):電商數倉(四十二)之系統業務資料倉庫(十五)商品每日銷量排行Top10

1 DWS

使用使用者購買商品明細寬表作為DWS資料

2 ADS

2.1 建表語句

drop table if exists ads_goods_order_count_day;
create external table ads_goods_order_count_day(   
    dt string comment '統計日期',
    sku_id   string  comment '商品id',
    order_count bigint comment '下單次數'
) COMMENT '商品下單top10'
stored as parquet
location 
'/warehouse/gmall/dws/ads_goods_order_count_day/';
View Code

2.2 匯入資料

-----------------------------需求-商品每日下單排行Top10----------------------
-----------------------------相關表---------------------
dws_sale_detail_daycount: 每個使用者每天的購買的商品明細
-----------------------------思路-----------------------
求今日的銷售明細,按商品分組,統計數量,排序取前十

-----------------------------SQL------------------------
insert into TABLE ads_goods_order_count_day
select
'2020-02-16',sku_id,count(*) order_count
from dws_sale_detail_daycount
where dt='2020-02-16'
group by sku_id
order by order_count desc
limit 10