Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
zruiquan committed Nov 19, 2024
1 parent dca1b3c commit c5eaf23
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 165 deletions.
260 changes: 95 additions & 165 deletions source/_posts/电商数仓项目-电商数据仓库系统4.md
Original file line number Diff line number Diff line change
Expand Up @@ -11510,6 +11510,20 @@ on page.recent_days=pay.recent_days;

### 11.2.5 新增下单用户统计

![image-20241119215605253](电商数仓项目-电商数据仓库系统4/image-20241119215605253.png)

![image-20241119220129455](电商数仓项目-电商数据仓库系统4/image-20241119220129455.png)

![image-20241119220233476](电商数仓项目-电商数据仓库系统4/image-20241119220233476.png)

![image-20241119220253301](电商数仓项目-电商数据仓库系统4/image-20241119220253301.png)

![image-20241119220323076](电商数仓项目-电商数据仓库系统4/image-20241119220323076.png)

![image-20241119220347085](电商数仓项目-电商数据仓库系统4/image-20241119220347085.png)



需求说明如下。

| 统计周期 | 指标 | 说明 |
Expand All @@ -11518,23 +11532,17 @@ on page.recent_days=pay.recent_days;

**1)建表语句**

```sql
DROP TABLE IF EXISTS ads_new_order_user_stats;

CREATE EXTERNAL TABLE ads_new_order_user_stats

(

`dt` STRING COMMENT '统计日期',

`recent_days` BIGINT COMMENT '最近天数,1:最近1天,7:最近7天,30:最近30天',

`new_order_user_count` BIGINT COMMENT '新增下单人数'

`dt` STRING COMMENT '统计日期',
`recent_days` BIGINT COMMENT '最近天数,1:最近1天,7:最近7天,30:最近30天',
`new_order_user_count` BIGINT COMMENT '新增下单人数'
) COMMENT '新增下单用户统计'

ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t'

LOCATION '/warehouse/gmall/ads/ads_new_order_user_stats/';
ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t'
LOCATION '/warehouse/gmall/ads/ads_new_order_user_stats/';
```

**2)数据装载**

Expand All @@ -11552,27 +11560,19 @@ LOCATION '/warehouse/gmall/ads/ads_new_order_user_stats/';

(4)代码实现

```sql
insert overwrite table ads_new_order_user_stats

select * from ads_new_order_user_stats

union

select

'2022-06-08' dt,

recent_days,

count(*) new_order_user_count

'2022-06-08' dt,
recent_days,
count(*) new_order_user_count
from dws_trade_user_order_td lateral view explode(array(1,7,30)) tmp as recent_days

where dt='2022-06-08'

and order_date_first>=date_add('2022-06-08',-recent_days+1)

group by recent_days;
```

### 11.2.6 最近7日内连续3日下单用户数

Expand Down Expand Up @@ -12096,37 +12096,24 @@ from

**1)建表语句**

```sql
DROP TABLE IF EXISTS ads_order_stats_by_cate;

CREATE EXTERNAL TABLE ads_order_stats_by_cate

(

`dt` STRING COMMENT '统计日期',

`recent_days` BIGINT COMMENT '最近天数,1:最近1天,7:最近7天,30:最近30天',

`category1_id` STRING COMMENT '一级品类ID',

`category1_name` STRING COMMENT '一级品类名称',

`category2_id` STRING COMMENT '二级品类ID',

`category2_name` STRING COMMENT '二级品类名称',

`category3_id` STRING COMMENT '三级品类ID',

`category3_name` STRING COMMENT '三级品类名称',

`order_count` BIGINT COMMENT '下单数',

`order_user_count` BIGINT COMMENT '下单人数'

`dt` STRING COMMENT '统计日期',
`recent_days` BIGINT COMMENT '最近天数,1:最近1天,7:最近7天,30:最近30天',
`category1_id` STRING COMMENT '一级品类ID',
`category1_name` STRING COMMENT '一级品类名称',
`category2_id` STRING COMMENT '二级品类ID',
`category2_name` STRING COMMENT '二级品类名称',
`category3_id` STRING COMMENT '三级品类ID',
`category3_name` STRING COMMENT '三级品类名称',
`order_count` BIGINT COMMENT '下单数',
`order_user_count` BIGINT COMMENT '下单人数'
) COMMENT '各品类商品下单统计'

ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t'

LOCATION '/warehouse/gmall/ads/ads_order_stats_by_cate/';
ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t'
LOCATION '/warehouse/gmall/ads/ads_order_stats_by_cate/';
```

**2)数据装载**

Expand All @@ -12144,125 +12131,68 @@ LOCATION '/warehouse/gmall/ads/ads_order_stats_by_cate/';

(4)代码实现

```sql
insert overwrite table ads_order_stats_by_cate

select * from ads_order_stats_by_cate

union

select

'2022-06-08' dt,

recent_days,

category1_id,

category1_name,

category2_id,

category2_name,

category3_id,

category3_name,

order_count,

order_user_count

from

(

select

1 recent_days,

category1_id,

category1_name,

category2_id,

category2_name,

category3_id,

category3_name,

sum(order_count_1d) order_count,

count(distinct(user_id)) order_user_count

from dws_trade_user_sku_order_1d

where dt='2022-06-08'

group by category1_id,category1_name,category2_id,category2_name,category3_id,category3_name

union all

select

recent_days,

category1_id,

category1_name,

category2_id,

category2_name,

category3_id,

category3_name,

sum(order_count),

count(distinct(if(order_count>0,user_id,null)))

'2022-06-08' dt,
recent_days,
category1_id,
category1_name,
category2_id,
category2_name,
category3_id,
category3_name,
order_count,
order_user_count
from

(

select

recent_days,

user_id,

category1_id,

category1_name,

category2_id,

category2_name,

category3_id,

category3_name,

case recent_days

when 7 then order_count_7d

when 30 then order_count_30d

end order_count

from dws_trade_user_sku_order_nd lateral view explode(array(7,30)) tmp as recent_days

where dt='2022-06-08'

)t1

group by recent_days,category1_id,category1_name,category2_id,category2_name,category3_id,category3_name

select
1 recent_days,
category1_id,
category1_name,
category2_id,
category2_name,
category3_id,
category3_name,
sum(order_count_1d) order_count,
count(distinct(user_id)) order_user_count
from dws_trade_user_sku_order_1d
where dt='2022-06-08'
group by category1_id,category1_name,category2_id,category2_name,category3_id,category3_name
union all
select
recent_days,
category1_id,
category1_name,
category2_id,
category2_name,
category3_id,
category3_name,
sum(order_count),
count(distinct(if(order_count>0,user_id,null)))
from
(
select
recent_days,
user_id,
category1_id,
category1_name,
category2_id,
category2_name,
category3_id,
category3_name,
case recent_days
when 7 then order_count_7d
when 30 then order_count_30d
end order_count
from dws_trade_user_sku_order_nd lateral view explode(array(7,30)) tmp as recent_days
where dt='2022-06-08'
)t1
group by recent_days,category1_id,category1_name,category2_id,category2_name,category3_id,category3_name
)odr;
```

### 11.3.4 各品类商品购物车存量Top3

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit c5eaf23

Please sign in to comment.