|
@@ -154,7 +154,8 @@ select
|
|
|
dt,channel,pitcher,stage,platform,book,
|
|
|
order_count,order_user,order_amount,first_order_count,first_order_user,first_order_amount,
|
|
|
view_count,click_count,follow_user,cost,reg_order_count,reg_order_user,reg_order_amount,reg_order_amount30,
|
|
|
- web_view_count,platform_view_count,web_order_count,total_cost,total_amount,reg_order_user_again,reg_order_user7,reg_order_user30,reg_order_amount7,type
|
|
|
+ web_view_count,platform_view_count,web_order_count,total_cost,total_amount,reg_order_user_again,reg_order_user7,reg_order_user30,reg_order_amount7,type,
|
|
|
+ total_first_amount
|
|
|
from
|
|
|
(select dt,channel, pitcher,stage,platform,book,cost,view_count,click_count,follow_user,web_view_count,platform_view_count,web_order_count,type from dw_daily_channel_cost) a
|
|
|
left outer join
|
|
@@ -182,7 +183,7 @@ from
|
|
|
from order group by date,channel) d
|
|
|
on dt=dt4 and channel=channel4
|
|
|
left outer join
|
|
|
- (select dt dt5,channel channel5,total_cost,total_amount from dw_channel_daily_total ) e
|
|
|
+ (select dt dt5,channel channel5,total_cost,total_amount,total_first_amount from dw_channel_daily_total ) e
|
|
|
on dt=dt5 and channel=channel5
|
|
|
|
|
|
left outer join (
|
|
@@ -284,17 +285,39 @@ having pitcher != ''"""
|
|
|
|
|
|
def dw_channel_daily_total(ymd):
|
|
|
sql=f"""insert into dw_channel_daily_total
|
|
|
- select '{ymd}' dt,channel,total_cost,total_amount from
|
|
|
+ select '{ymd}' dt,channel,total_cost,total_amount,total_first_amount from
|
|
|
(select channel,sum(cost) total_cost from dw_daily_channel_cost where dt<='{ymd}' group by channel)a
|
|
|
left outer join
|
|
|
- (select channel,sum(amount) total_amount from order where date<='{ymd}' group by channel) b
|
|
|
- on a.channel=b.channel"""
|
|
|
+ (select channel,sum(amount) total_amount,
|
|
|
+ sum(if(toDate(formatDateTime(reg_time,'%Y-%m-%d'))=date,amount,0)) total_first_amount
|
|
|
+ from order where date<='{ymd}' group by channel) b
|
|
|
+ on a.channel=b.channel
|
|
|
+
|
|
|
+ """
|
|
|
ck.execute(f"alter table dw_channel_daily_total drop partition '{ymd}'")
|
|
|
+ print(sql)
|
|
|
+ ck.execute(sql)
|
|
|
+
|
|
|
+def dw_daily_pitcher(ymd):
|
|
|
+ sql=f"""insert into dw_daily_pitcher
|
|
|
+select '{ymd}' dt, a.pitcher,
|
|
|
+ start_cost_date,end_cost_date,
|
|
|
+ sum(if(dt>=start_cost_date,reg_order_amount,0)) total_amount,
|
|
|
+ sum(if(dt>=start_cost_date,cost,0)) total_cost
|
|
|
+from (select reg_order_amount,cost,dt,pitcher from dw_daily_channel where dt<='{ymd}')
|
|
|
+ a left outer join
|
|
|
+(select min(dt) start_cost_date,max(dt) end_cost_date,pitcher
|
|
|
+from dw_daily_channel_cost where cost>0 group by pitcher) b on a.pitcher=b.pitcher
|
|
|
+ group by pitcher,start_cost_date,end_cost_date
|
|
|
+"""
|
|
|
+ # print(sql)
|
|
|
+ ck.execute(f"alter table dw_daily_pitcher drop partition '{ymd}'")
|
|
|
ck.execute(sql)
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
+ # dw_channel_daily_total('2020-07-20')
|
|
|
# channel_by_account_daily('2020-12-17')
|
|
|
# dw_daily_channel_cost('2020-12-17')
|
|
|
# dw_order_channel_cost_sync_ck('2020-12-17')
|
|
@@ -302,19 +325,26 @@ if __name__ == '__main__':
|
|
|
# ods_order('2020-12-20')
|
|
|
# dw_daily_channel_plus()
|
|
|
# exit()
|
|
|
- # dw_daily_channel()
|
|
|
- # exit(0)
|
|
|
+ dw_daily_channel()
|
|
|
+ exit(0)
|
|
|
# dm_pitcher_daily_page_total()
|
|
|
# dm_pitcher_daily_page_total()
|
|
|
# dw_channel_daily_total('2021-01-11')
|
|
|
- dw_daily_channel_cost('2021-01-12')
|
|
|
- exit(0)
|
|
|
+ # dw_daily_channel_cost('2021-01-12')
|
|
|
+ # dw_channel_daily_total('2021-01-13')
|
|
|
+ # exit(0)
|
|
|
|
|
|
# dw_daily_channel()
|
|
|
# # exit(0)
|
|
|
- for i in dt.getDateLists('2019-03-18','2020-12-18'):
|
|
|
+ for i in dt.getDateLists('2019-03-18','2021-01-13'):
|
|
|
print(i)
|
|
|
- channel_by_account_daily(i)
|
|
|
+ dw_channel_daily_total(i)
|
|
|
+ # dw_daily_pitcher(i)
|
|
|
+ # channel_by_account_daily(i)
|
|
|
+ # dw_daily_channel_cost(i)
|
|
|
+ # dw_order_channel_cost_sync_ck(i)
|
|
|
+ # dw_daily_channel()
|
|
|
+
|
|
|
# order_sync_ck(today)
|
|
|
# # ods_order(i)
|
|
|
# channel_info_daily(i)
|