|  | @@ -203,7 +203,7 @@ def dm_pitcher_daily_page_total():
 | 
	
		
			
				|  |  |      sql=f"""
 | 
	
		
			
				|  |  |  insert into dm_pitcher_daily_page_total
 | 
	
		
			
				|  |  |  select '{dt.get_n_days(0)}' dt,
 | 
	
		
			
				|  |  | -       pitcher,
 | 
	
		
			
				|  |  | +       q.pitcher,
 | 
	
		
			
				|  |  |         round(cost,2),
 | 
	
		
			
				|  |  |         round(amount,2),
 | 
	
		
			
				|  |  |         round(roi,4),
 | 
	
	
		
			
				|  | @@ -226,7 +226,7 @@ from (select pitcher,
 | 
	
		
			
				|  |  |               if(cost = 0, 0, round(amount / cost, 2)) roi
 | 
	
		
			
				|  |  |        from dw_daily_channel
 | 
	
		
			
				|  |  |        group by pitcher) q
 | 
	
		
			
				|  |  | -         left outer join
 | 
	
		
			
				|  |  | +        left outer join
 | 
	
		
			
				|  |  |       (select count(distinct channel) channel_count, pitcher
 | 
	
		
			
				|  |  |        from dw_daily_channel_cost
 | 
	
		
			
				|  |  |        where dt = '{dt.get_n_days(0)}'
 | 
	
	
		
			
				|  | @@ -275,9 +275,7 @@ left outer join (
 | 
	
		
			
				|  |  |      where reg_time >= '{dt.get_n_pre_month_first_day(0)} 00:00:00' 
 | 
	
		
			
				|  |  |      group by pitcher
 | 
	
		
			
				|  |  |  ) g on q.pitcher=g.pitcher
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -having pitcher != ''"""
 | 
	
		
			
				|  |  | +"""
 | 
	
		
			
				|  |  |      print(sql)
 | 
	
		
			
				|  |  |      ck.execute(f"alter table dm_pitcher_daily_page_total drop partition '{dt.get_n_days(0)}'")
 | 
	
		
			
				|  |  |      ck.execute(sql)
 | 
	
	
		
			
				|  | @@ -299,7 +297,9 @@ def dw_channel_daily_total(ymd):
 | 
	
		
			
				|  |  |      ck.execute(sql)
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  def dw_daily_pitcher(ymd):
 | 
	
		
			
				|  |  | -    sql=f"""select '{ymd}' dt, a.pitcher,
 | 
	
		
			
				|  |  | +    sql=f"""
 | 
	
		
			
				|  |  | +insert into dw_daily_pitcher
 | 
	
		
			
				|  |  | +select '{ymd}' dt, a.pitcher,
 | 
	
		
			
				|  |  |         start_cost_date,end_cost_date,total_amount,total_cost
 | 
	
		
			
				|  |  |  from
 | 
	
		
			
				|  |  |       (select sum(cost) total_cost,pitcher from dw_daily_channel_cost where dt<='{ymd}' group by pitcher) a
 | 
	
	
		
			
				|  | @@ -307,13 +307,15 @@ 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
 | 
	
		
			
				|  |  |  left outer join
 | 
	
		
			
				|  |  | -    (select pitcher,sum(if(toDate(formatDateTime(reg_time,'%Y-%m-%d'))>=start_cost_date,amount,0)) total_amount 
 | 
	
		
			
				|  |  | +    (
 | 
	
		
			
				|  |  | +    select b.pitcher pitcher,sum(if(toDate(formatDateTime(reg_time,'%Y-%m-%d'))>=start_cost_date,amount,0)) total_amount
 | 
	
		
			
				|  |  |      from order a
 | 
	
		
			
				|  |  |      left outer join dw_daily_channel_cost b on a.channel = b.channel and date=dt
 | 
	
		
			
				|  |  | -    left outer join (select  min(dt) start_cost_date,pitcher from dw_daily_channel_cost  where cost>0   group by pitcher) c on b.pitcher=c.pitcher
 | 
	
		
			
				|  |  | -    where date<='{ymd}' group by pitcher) c on a.pitcher=c.pitcher;
 | 
	
		
			
				|  |  | +    left outer join (select  min(dt) start_cost_date,pitcher,channel from dw_daily_channel_cost  where cost>0   group by pitcher,channel)
 | 
	
		
			
				|  |  | +        c on b.pitcher=c.pitcher and b.channel=c.channel where date<='{ymd}' group by b.pitcher
 | 
	
		
			
				|  |  | +) d on a.pitcher=d.pitcher
 | 
	
		
			
				|  |  |  """
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | +    print(sql)
 | 
	
		
			
				|  |  |      ck.execute(f"alter table dw_daily_pitcher drop partition '{ymd}'")
 | 
	
		
			
				|  |  |      ck.execute(sql)
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -321,7 +323,8 @@ left outer join
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  if __name__ == '__main__':
 | 
	
		
			
				|  |  |      # dw_daily_pitcher('2021-01-14')
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | +    dm_pitcher_daily_page_total()
 | 
	
		
			
				|  |  | +    exit(0)
 | 
	
		
			
				|  |  |      # dw_channel_daily_total('2020-07-20')
 | 
	
		
			
				|  |  |      # channel_by_account_daily('2020-12-17')
 | 
	
		
			
				|  |  |      # dw_daily_channel_cost('2020-12-17')
 | 
	
	
		
			
				|  | @@ -342,7 +345,7 @@ if __name__ == '__main__':
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      # dw_daily_channel()
 | 
	
		
			
				|  |  |      # # exit(0)
 | 
	
		
			
				|  |  | -    for i in dt.getDateLists('2019-09-18','2021-01-13'):
 | 
	
		
			
				|  |  | +    for i in dt.getDateLists('2019-03-18','2021-01-14'):
 | 
	
		
			
				|  |  |          print(i)
 | 
	
		
			
				|  |  |          # dw_channel_daily_total(i)
 | 
	
		
			
				|  |  |          dw_daily_pitcher(i)
 |