INSERT INTO TABLE internal_platform_db.ads_gy_digital_tool_used_plat_data_d_ql_query_engine_143 ( imp_date ,`fundraising_platform` ,`stat_date` ,`total_org_cnt` ,`total_pid_org_cnt` ,`total_pid_cnt` ,`total_user_org_cnt` ,`total_user_pid_cnt` ,`total_user_cnt` ,`total_agent_cnt` ,`total_platformw_auth_user_cnt` ,`total_bank_auth_user_cnt` ,`total_transfer_amount` ,`total_platformw_transfer_amount` ,`total_bank_transfer_amount` ,`total_transfer_cnt` ,`total_platformw_transfer_cnt` ,`total_bank_transfer_cnt` ,`total_transfer_org_cnt` ,`total_platformw_transfer_org_cnt` ,`total_bank_transfer_org_cnt` ,`total_transfer_pid_cnt` ,`total_platformw_transfer_pid_cnt` ,`total_bank_transfer_pid_cnt` ,`total_transfer_user_cnt` ,`total_platformw_transfer_user_cnt` ,`total_bank_transfer_user_cnt` ,`new_org_cnt` ,`new_pid_org_cnt` ,`new_pid_cnt` ,`new_user_org_cnt` ,`new_user_pid_cnt` ,`new_user_cnt` ,`new_agent_cnt` ,`new_platformw_auth_user_cnt` ,`new_bank_auth_user_cnt` ,`new_transfer_amount` ,`new_platformw_transfer_amount` ,`new_bank_transfer_amount` ,`new_transfer_cnt` ,`new_platformw_transfer_cnt` ,`new_bank_transfer_cnt` ,`new_transfer_org_cnt` ,`new_platformw_transfer_org_cnt` ,`new_bank_transfer_org_cnt` ,`new_transfer_pid_cnt` ,`new_platformw_transfer_pid_cnt` ,`new_bank_transfer_pid_cnt` ,`new_transfer_user_cnt` ,`new_platformw_transfer_user_cnt` ,`new_bank_transfer_user_cnt` )with org_pid_data as ( select * , row_number() over (partition by ds_org_id order by org_create_date) as org_rk , row_number() over (partition by fundraising_platform,ds_org_id order by org_create_date) as org_plat_rk , row_number() over (partition by ds_org_id,is_org_pid order by org_create_date) as org_pid_rk , row_number() over (partition by fundraising_platform,ds_org_id,is_org_pid order by org_create_date) as org_pid_plat_rk , row_number() over (partition by ds_project_id order by pid_create_date) as pid_rk , row_number() over (partition by fundraising_platform,ds_project_id order by pid_create_date) as pid_plat_rk from ( select case when b.fundraising_platform = 2 then '慈善平台X' else '其他平台' end as fundraising_platform , b.ds_project_id , a.ds_org_id , substring(a.create_time,1,10) as org_create_date , substring(b.create_time,1,10) as pid_create_date , case when b.ds_project_id is not null then 1 else 0 end as is_org_pid from ( select ds_org_id , create_time from internal_platform_db.dim_ds_org_info_d_ql_query_engine_143 where imp_date = 20260608 and is_test_org = 0 ) a left join ( select ds_org_id , ds_project_id , create_time , fundraising_platform from internal_platform_db.dim_ds_project_info_d_ql_query_engine_143 where imp_date = 20260608 and is_test_project = 0 ) b on a.ds_org_id = b.ds_org_id ) ), user_data as ( select * , row_number() over (partition by ds_org_id order by user_create_date) as org_rk , row_number() over (partition by fundraising_platform,ds_org_id order by user_create_date) as org_plat_rk , row_number() over (partition by ds_project_id order by user_create_date) as pid_rk , row_number() over (partition by fundraising_platform,ds_project_id order by user_create_date) as pid_plat_rk , row_number() over (partition by ds_grantee_id order by user_create_date) as user_rk , row_number() over (partition by fundraising_platform,ds_grantee_id order by user_create_date) as user_plat_rk , row_number() over (partition by ds_grantee_id,is_platformw_auth order by platformw_auth_date) as user_auth_rk , row_number() over (partition by fundraising_platform,ds_grantee_id,is_platformw_auth order by platformw_auth_date) as user_plat_auth_rk , row_number() over (partition by ds_grantee_id,is_bank_auth order by user_create_date) as user_bank_auth_rk , row_number() over (partition by fundraising_platform,ds_grantee_id,is_bank_auth order by user_create_date) as user_plat_bank_auth_rk , row_number() over (partition by ds_agent_id order by user_create_date) as agent_rk , row_number() over (partition by fundraising_platform,ds_agent_id order by user_create_date) as agent_plat_rk from ( select case when b.fundraising_platform = 2 then '慈善平台X' else '其他平台' end as fundraising_platform , b.ds_project_id , b.ds_org_id , a.ds_grantee_id , a.ds_agent_id , substring(a.create_time,1,10) as user_create_date , case when a.platformw_auth_time <> '' and a.agent_platformw_auth_time <> '' then least(substring(a.platformw_auth_time,1,10),substring(a.agent_platformw_auth_time,1,10)) when a.platformw_auth_time <> '' and a.agent_platformw_auth_time = '' then substring(a.platformw_auth_time,1,10) else substring(a.agent_platformw_auth_time,1,10) end as platformw_auth_date , case when coalesce(a.bank_account,'') != '' then 1 else 0 end as is_bank_auth , case when (coalesce(a.platformw_auth_time,'') != '' and coalesce(a.open_id,'') != '') or (coalesce(a.agent_platformw_auth_time,'') != '' and coalesce(a.agent_open_id,'') != '') then 1 else 0 end as is_platformw_auth from internal_platform_db.dim_ds_grantee_data_d_ql_query_engine_143 a join internal_platform_db.dim_ds_project_info_d_ql_query_engine_143 b on a.ds_project_id = b.ds_project_id where a.imp_date = 20260608 and b.imp_date = 20260608 and a.ds_grantee_state in (0,1) and b.is_test_project = 0 ) ), transfer_data as ( select * , row_number() over (partition by ds_org_id order by transfer_date) as org_rk , row_number() over (partition by ds_org_id,transfer_mode order by transfer_date) as org_mode_rk , row_number() over (partition by fundraising_platform,ds_org_id order by transfer_date) as org_plat_rk , row_number() over (partition by fundraising_platform,ds_org_id,transfer_mode order by transfer_date) as org_plat_mode_rk , row_number() over (partition by ds_project_id order by transfer_date) as pid_rk , row_number() over (partition by ds_project_id,transfer_mode order by transfer_date) as pid_mode_rk , row_number() over (partition by fundraising_platform,ds_project_id order by transfer_date) as pid_plat_rk , row_number() over (partition by fundraising_platform,ds_project_id,transfer_mode order by transfer_date) as pid_plat_mode_rk , row_number() over (partition by ds_grantee_id order by transfer_date) as user_rk , row_number() over (partition by fundraising_platform,ds_grantee_id order by transfer_date) as user_plat_rk , row_number() over (partition by ds_grantee_id,transfer_mode order by transfer_date) as user_mode_rk , row_number() over (partition by fundraising_platform,ds_grantee_id,transfer_mode order by transfer_date) as user_plat_mode_rk from ( select case when b.fundraising_platform = 2 then '慈善平台X' else '其他平台' end as fundraising_platform , case when a.transfer_mode = 1 then substring(a.trans_succ_time,1,10) else substring(a.create_time,1,10) end as transfer_date , b.ds_project_id , b.ds_org_id , a.ds_grantee_id , a.transfer_amount , a.transfer_mode , a.id from internal_platform_db.dwd_project_ds_transfer_log_d_ql_query_engine_143 a join internal_platform_db.dim_ds_project_info_d_ql_query_engine_143 b on a.ds_project_id = b.ds_project_id where a.imp_date = 20260608 and b.imp_date = 20260608 and a.transfer_state = 2 and b.is_test_project = 0 ) ) select 20260608 as imp_date , fundraising_platform , stat_date , max(coalesce(total_org_cnt,0)) as total_org_cnt , max(coalesce(total_pid_org_cnt,0)) as total_pid_org_cnt , max(coalesce(total_pid_cnt,0)) as total_pid_cnt , max(coalesce(total_user_org_cnt,0)) as total_user_org_cnt , max(coalesce(total_user_pid_cnt,0)) as total_user_pid_cnt , max(coalesce(total_user_cnt,0)) as total_user_cnt , max(coalesce(total_agent_cnt,0)) as total_agent_cnt , max(coalesce(total_platformw_auth_user_cnt,0)) as total_platformw_auth_user_cnt , max(coalesce(total_bank_auth_user_cnt,0)) as total_bank_auth_user_cnt , max(coalesce(total_transfer_amount,0)) as total_transfer_amount , max(coalesce(total_platformw_transfer_amount,0)) as total_platformw_transfer_amount , max(coalesce(total_bank_transfer_amount,0)) as total_bank_transfer_amount , max(coalesce(total_transfer_cnt,0)) as total_transfer_cnt , max(coalesce(total_platformw_transfer_cnt,0)) as total_platformw_transfer_cnt , max(coalesce(total_bank_transfer_cnt,0)) as total_bank_transfer_cnt , max(coalesce(total_transfer_org_cnt,0)) as total_transfer_org_cnt , max(coalesce(total_platformw_transfer_org_cnt,0)) as total_platformw_transfer_org_cnt , max(coalesce(total_bank_transfer_org_cnt,0)) as total_bank_transfer_org_cnt , max(coalesce(total_transfer_pid_cnt,0)) as total_transfer_pid_cnt , max(coalesce(total_platformw_transfer_pid_cnt,0)) as total_platformw_transfer_pid_cnt , max(coalesce(total_bank_transfer_pid_cnt,0)) as total_bank_transfer_pid_cnt , max(coalesce(total_transfer_user_cnt,0)) as total_transfer_user_cnt , max(coalesce(total_platformw_transfer_user_cnt,0)) as total_platformw_transfer_user_cnt , max(coalesce(total_bank_transfer_user_cnt,0)) as total_bank_transfer_user_cnt , max(coalesce(new_org_cnt,0)) as new_org_cnt , max(coalesce(new_pid_org_cnt,0)) as new_pid_org_cnt , max(coalesce(new_pid_cnt,0)) as new_pid_cnt , max(coalesce(new_user_org_cnt,0)) as new_user_org_cnt , max(coalesce(new_user_pid_cnt,0)) as new_user_pid_cnt , max(coalesce(new_user_cnt,0)) as new_user_cnt , max(coalesce(new_agent_cnt,0)) as new_agent_cnt , max(coalesce(new_platformw_auth_user_cnt,0)) as new_platformw_auth_user_cnt , max(coalesce(new_bank_auth_user_cnt,0)) as new_bank_auth_user_cnt , max(coalesce(new_transfer_amount,0)) as new_transfer_amount , max(coalesce(new_platformw_transfer_amount,0)) as new_platformw_transfer_amount , max(coalesce(new_bank_transfer_amount,0)) as new_bank_transfer_amount , max(coalesce(new_transfer_cnt,0)) as new_transfer_cnt , max(coalesce(new_platformw_transfer_cnt,0)) as new_platformw_transfer_cnt , max(coalesce(new_bank_transfer_cnt,0)) as new_bank_transfer_cnt , max(coalesce(new_transfer_org_cnt,0)) as new_transfer_org_cnt , max(coalesce(new_platformw_transfer_org_cnt,0)) as new_platformw_transfer_org_cnt , max(coalesce(new_bank_transfer_org_cnt,0)) as new_bank_transfer_org_cnt , max(coalesce(new_transfer_pid_cnt,0)) as new_transfer_pid_cnt , max(coalesce(new_platformw_transfer_pid_cnt,0)) as new_platformw_transfer_pid_cnt , max(coalesce(new_bank_transfer_pid_cnt,0)) as new_bank_transfer_pid_cnt , max(coalesce(new_transfer_user_cnt,0)) as new_transfer_user_cnt , max(coalesce(new_platformw_transfer_user_cnt,0)) as new_platformw_transfer_user_cnt , max(coalesce(new_bank_transfer_user_cnt,0)) as new_bank_transfer_user_cnt from ( select '所有平台' as fundraising_platform , org_create_date as stat_date , max(total_org_cnt) as total_org_cnt , max(total_pid_org_cnt) as total_pid_org_cnt , max(total_pid_cnt) as total_pid_cnt , 0 as total_user_org_cnt , 0 as total_user_pid_cnt , 0 as total_user_cnt , 0 as total_agent_cnt , 0 as total_platformw_auth_user_cnt , 0 as total_bank_auth_user_cnt , 0 as total_transfer_amount , 0 as total_platformw_transfer_amount , 0 as total_bank_transfer_amount , 0 as total_transfer_cnt , 0 as total_platformw_transfer_cnt , 0 as total_bank_transfer_cnt , 0 as total_transfer_org_cnt , 0 as total_platformw_transfer_org_cnt , 0 as total_bank_transfer_org_cnt , 0 as total_transfer_pid_cnt , 0 as total_platformw_transfer_pid_cnt , 0 as total_bank_transfer_pid_cnt , 0 as total_transfer_user_cnt , 0 as total_platformw_transfer_user_cnt , 0 as total_bank_transfer_user_cnt , count(case when org_rk = 1 then ds_org_id end) as new_org_cnt , 0 as new_pid_org_cnt , 0 as new_pid_cnt , 0 as new_user_org_cnt , 0 as new_user_pid_cnt , 0 as new_user_cnt , 0 as new_agent_cnt , 0 as new_platformw_auth_user_cnt , 0 as new_bank_auth_user_cnt , 0 as new_transfer_amount , 0 as new_platformw_transfer_amount , 0 as new_bank_transfer_amount , 0 as new_transfer_cnt , 0 as new_platformw_transfer_cnt , 0 as new_bank_transfer_cnt , 0 as new_transfer_org_cnt , 0 as new_platformw_transfer_org_cnt , 0 as new_bank_transfer_org_cnt , 0 as new_transfer_pid_cnt , 0 as new_platformw_transfer_pid_cnt , 0 as new_bank_transfer_pid_cnt , 0 as new_transfer_user_cnt , 0 as new_platformw_transfer_user_cnt , 0 as new_bank_transfer_user_cnt from ( select * , count(case when org_rk = 1 then ds_org_id end) over (partition by 1) as total_org_cnt , count(case when is_org_pid = 1 and org_pid_rk = 1 then ds_org_id end) over (partition by 1) as total_pid_org_cnt , count(case when pid_rk = 1 then ds_project_id end) over (partition by 1) as total_pid_cnt from org_pid_data ) a group by org_create_date union all select fundraising_platform , org_create_date as org_date , 0 as total_org_cnt , max(total_pid_org_cnt) as total_pid_org_cnt , max(total_pid_cnt) as total_pid_cnt , 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 , count(case when org_plat_rk = 1 then ds_org_id end) as new_org_cnt , 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 from ( select * , count(case when org_plat_rk = 1 then ds_org_id end) over (partition by fundraising_platform) as total_org_cnt , count(case when is_org_pid = 1 and org_pid_plat_rk = 1 then ds_org_id end) over (partition by fundraising_platform) as total_pid_org_cnt , count(case when pid_plat_rk = 1 then ds_project_id end) over (partition by fundraising_platform) as total_pid_cnt from org_pid_data ) a group by fundraising_platform , org_create_date union all select '所有平台' as fundraising_platform , pid_create_date , 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 , 0 , count(case when is_org_pid = 1 and org_pid_rk = 1 then ds_org_id end) as new_pid_org_cnt , count(case when pid_rk = 1 then ds_project_id end) as new_pid_cnt , 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 from org_pid_data group by pid_create_date union all select fundraising_platform , pid_create_date , 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 , 0 , count(case when is_org_pid = 1 and org_pid_plat_rk = 1 then ds_org_id end) as new_pid_org_cnt , count(case when pid_plat_rk = 1 then ds_project_id end) as new_pid_cnt , 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 from org_pid_data group by fundraising_platform , pid_create_date union all select '所有平台' as fundraising_platform , user_create_date as user_date , 0,0,0 , max(total_user_org_cnt) as total_user_org_cnt , max(total_user_pid_cnt) as total_user_pid_cnt , max(total_user_cnt) as total_user_cnt , max(total_agent_cnt) as total_agent_cnt , max(total_platformw_auth_user_cnt) as total_platformw_auth_user_cnt , max(total_bank_auth_user_cnt) as total_bank_auth_user_cnt , 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 , 0,0,0 , count(case when org_rk = 1 then ds_org_id end) as new_user_org_cnt , count(case when pid_rk = 1 then ds_project_id end) as new_user_pid_cnt , count(case when user_rk = 1 then ds_grantee_id end) as new_user_cnt , count(case when agent_rk = 1 then ds_agent_id end) as new_agent_cnt , 0 as new_platformw_auth_user_cnt , count(case when is_bank_auth = 1 and user_bank_auth_rk = 1 then ds_grantee_id end) as new_bank_auth_user_cnt , 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 from ( select * , count(case when org_rk = 1 then ds_org_id end) over (partition by 1) as total_user_org_cnt , count(case when pid_rk = 1 then ds_project_id end) over (partition by 1) as total_user_pid_cnt , count(case when user_rk = 1 then ds_grantee_id end) over (partition by 1) as total_user_cnt , count(case when agent_rk = 1 then ds_agent_id end) over (partition by 1) as total_agent_cnt , count(case when is_platformw_auth = 1 and user_auth_rk = 1 then ds_grantee_id end) over (partition by 1) as total_platformw_auth_user_cnt , count(case when is_bank_auth = 1 and user_bank_auth_rk = 1 then ds_grantee_id end) over (partition by 1) as total_bank_auth_user_cnt from user_data ) a group by user_create_date union all select fundraising_platform , user_create_date , 0,0,0 , max(total_user_org_cnt) as total_user_org_cnt , max(total_user_pid_cnt) as total_user_pid_cnt , max(total_user_cnt) as total_user_cnt , max(total_agent_cnt) as total_agent_cnt , max(total_platformw_auth_user_cnt) as total_platformw_auth_user_cnt , max(total_bank_auth_user_cnt) as total_bank_auth_user_cnt , 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 , 0,0,0 , count(case when org_plat_rk = 1 then ds_org_id end) as new_user_org_cnt , count(case when pid_plat_rk = 1 then ds_project_id end) as new_user_pid_cnt , count(case when user_plat_rk = 1 then ds_grantee_id end) as new_user_cnt , count(case when agent_plat_rk = 1 then ds_agent_id end) as new_agent_cnt , 0 as new_platformw_auth_user_cnt , count(case when is_bank_auth = 1 and user_plat_bank_auth_rk = 1 then ds_grantee_id end) as new_bank_auth_user_cnt , 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 from ( select * , count(case when org_plat_rk = 1 then ds_org_id end) over (partition by fundraising_platform) as total_user_org_cnt , count(case when pid_plat_rk = 1 then ds_project_id end) over (partition by fundraising_platform) as total_user_pid_cnt , count(case when user_plat_rk = 1 then ds_grantee_id end) over (partition by fundraising_platform) as total_user_cnt , count(case when agent_plat_rk = 1 then ds_agent_id end) over (partition by fundraising_platform) as total_agent_cnt , count(case when is_platformw_auth = 1 and user_plat_auth_rk = 1 then ds_grantee_id end) over (partition by fundraising_platform) as total_platformw_auth_user_cnt , count(case when is_bank_auth = 1 and user_plat_bank_auth_rk = 1 then ds_grantee_id end) over (partition by fundraising_platform) as total_bank_auth_user_cnt from user_data ) a group by fundraising_platform , user_create_date union all select '所有平台' as fundraising_platform , platformw_auth_date , 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 , 0,0,0 , 0,0,0,0 , count(case when is_platformw_auth = 1 and user_plat_auth_rk = 1 then ds_grantee_id end) as new_platformw_auth_user_cnt , 0 , 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 from user_data group by platformw_auth_date union all select fundraising_platform , platformw_auth_date , 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 , 0,0,0 , 0,0,0,0 , count(case when is_platformw_auth = 1 and user_plat_auth_rk = 1 then ds_grantee_id end) as new_platformw_auth_user_cnt , 0 , 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 from user_data group by fundraising_platform , platformw_auth_date union all select '所有平台' as fundraising_platform , transfer_date , 0,0,0,0,0,0,0,0,0 , max(total_transfer_amount) as total_transfer_amount , max(total_platformw_transfer_amount) as total_platformw_transfer_amount , max(total_bank_transfer_amount) as total_bank_transfer_amount , max(total_transfer_cnt) as total_transfer_cnt , max(total_platformw_transfer_cnt) as total_platformw_transfer_cnt , max(total_bank_transfer_cnt) as total_bank_transfer_cnt , max(total_transfer_org_cnt) as total_transfer_org_cnt , max(total_platformw_transfer_org_cnt) as total_platformw_transfer_org_cnt , max(total_bank_transfer_org_cnt) as total_bank_transfer_org_cnt , max(total_transfer_pid_cnt) as total_transfer_pid_cnt , max(total_platformw_transfer_pid_cnt) as total_platformw_transfer_pid_cnt , max(total_bank_transfer_pid_cnt) as total_bank_transfer_pid_cnt , max(total_transfer_user_cnt) as total_transfer_user_cnt , max(total_platformw_transfer_user_cnt) as total_platformw_transfer_user_cnt , max(total_bank_transfer_user_cnt) as total_bank_transfer_user_cnt , 0,0,0,0,0,0,0,0,0 , sum(transfer_amount) as transfer_amount , sum(case when transfer_mode = 1 then transfer_amount end) as platformw_transfer_amount , sum(case when transfer_mode = 2 then transfer_amount end) as bank_transfer_amount , count(id) as transfer_cnt , count(case when transfer_mode = 1 then id end) as platformw_transfer_cnt , count(case when transfer_mode = 2 then id end) as bank_transfer_cnt , count(case when org_rk = 1 then ds_org_id end) as new_transfer_org_cnt , count(case when transfer_mode = 1 and org_mode_rk = 1 then ds_org_id end) as new_platformw_transfer_org_cnt , count(case when transfer_mode = 2 and org_mode_rk = 1 then ds_org_id end) as new_bank_transfer_org_cnt , count(case when pid_rk = 1 then ds_project_id end) as new_transfer_pid_cnt , count(case when transfer_mode = 1 and pid_mode_rk = 1 then ds_project_id end) as new_platformw_transfer_pid_cnt , count(case when transfer_mode = 2 and pid_mode_rk = 1 then ds_project_id end) as new_bank_transfer_pid_cnt , count(case when user_rk = 1 then ds_grantee_id end) as new_transfer_user_cnt , count(case when transfer_mode = 1 and user_mode_rk = 1 then ds_grantee_id end) as new_platformw_transfer_user_cnt , count(case when transfer_mode = 2 and user_mode_rk = 1 then ds_grantee_id end) as new_bank_transfer_user_cnt from ( select * , sum(transfer_amount) over (partition by 1) as total_transfer_amount , sum(case when transfer_mode = 1 then transfer_amount end) over (partition by 1) as total_platformw_transfer_amount , sum(case when transfer_mode = 2 then transfer_amount end) over (partition by 1) as total_bank_transfer_amount , count(id) over (partition by 1) as total_transfer_cnt , count(case when transfer_mode = 1 then id end) over (partition by 1) as total_platformw_transfer_cnt , count(case when transfer_mode = 2 then id end) over (partition by 1) as total_bank_transfer_cnt , count(case when org_rk = 1 then ds_org_id end) over (partition by 1) as total_transfer_org_cnt , count(case when transfer_mode = 1 and org_mode_rk = 1 then ds_org_id end) over (partition by 1) as total_platformw_transfer_org_cnt , count(case when transfer_mode = 2 and org_mode_rk = 1 then ds_org_id end) over (partition by 1) as total_bank_transfer_org_cnt , count(case when pid_rk = 1 then ds_project_id end) over (partition by 1) as total_transfer_pid_cnt , count(case when transfer_mode = 1 and pid_mode_rk = 1 then ds_project_id end) over (partition by 1) as total_platformw_transfer_pid_cnt , count(case when transfer_mode = 2 and pid_mode_rk = 1 then ds_project_id end) over (partition by 1) as total_bank_transfer_pid_cnt , count(case when user_rk = 1 then ds_grantee_id end) over (partition by 1) as total_transfer_user_cnt , count(case when transfer_mode = 1 and user_mode_rk = 1 then ds_grantee_id end) over (partition by 1) as total_platformw_transfer_user_cnt , count(case when transfer_mode = 2 and user_mode_rk = 1 then ds_grantee_id end) over (partition by 1) as total_bank_transfer_user_cnt from transfer_data ) a group by transfer_date union all select fundraising_platform , transfer_date , 0,0,0,0,0,0,0,0,0 , max(total_transfer_amount) as total_transfer_amount , max(total_platformw_transfer_amount) as total_platformw_transfer_amount , max(total_bank_transfer_amount) as total_bank_transfer_amount , max(total_transfer_cnt) as total_transfer_cnt , max(total_platformw_transfer_cnt) as total_platformw_transfer_cnt , max(total_bank_transfer_cnt) as total_bank_transfer_cnt , max(total_transfer_org_cnt) as total_transfer_org_cnt , max(total_platformw_transfer_org_cnt) as total_platformw_transfer_org_cnt , max(total_bank_transfer_org_cnt) as total_bank_transfer_org_cnt , max(total_transfer_pid_cnt) as total_transfer_pid_cnt , max(total_platformw_transfer_pid_cnt) as total_platformw_transfer_pid_cnt , max(total_bank_transfer_pid_cnt) as total_bank_transfer_pid_cnt , max(total_transfer_user_cnt) as total_transfer_user_cnt , max(total_platformw_transfer_user_cnt) as total_platformw_transfer_user_cnt , max(total_bank_transfer_user_cnt) as total_bank_transfer_user_cnt , 0,0,0,0,0,0,0,0,0 , sum(transfer_amount) as transfer_amount , sum(case when transfer_mode = 1 then transfer_amount end) as platformw_transfer_amount , sum(case when transfer_mode = 2 then transfer_amount end) as bank_transfer_amount , count(id) as transfer_cnt , count(case when transfer_mode = 1 then id end) as platformw_transfer_cnt , count(case when transfer_mode = 2 then id end) as bank_transfer_cnt , count(case when org_plat_rk = 1 then ds_org_id end) as new_transfer_org_cnt , count(case when transfer_mode = 1 and org_plat_mode_rk = 1 then ds_org_id end) as new_platformw_transfer_org_cnt , count(case when transfer_mode = 2 and org_plat_mode_rk = 1 then ds_org_id end) as new_bank_transfer_org_cnt , count(case when pid_plat_rk = 1 then ds_project_id end) as new_transfer_pid_cnt , count(case when transfer_mode = 1 and pid_plat_mode_rk = 1 then ds_project_id end) as new_platformw_transfer_pid_cnt , count(case when transfer_mode = 2 and pid_plat_mode_rk = 1 then ds_project_id end) as new_bank_transfer_pid_cnt , count(case when user_plat_rk = 1 then ds_grantee_id end) as new_transfer_user_cnt , count(case when transfer_mode = 1 and user_plat_mode_rk = 1 then ds_grantee_id end) as new_platformw_transfer_user_cnt , count(case when transfer_mode = 2 and user_plat_mode_rk = 1 then ds_grantee_id end) as new_bank_transfer_user_cnt from ( select * , sum(transfer_amount) over (partition by fundraising_platform) as total_transfer_amount , sum(case when transfer_mode = 1 then transfer_amount end) over (partition by fundraising_platform) as total_platformw_transfer_amount , sum(case when transfer_mode = 2 then transfer_amount end) over (partition by fundraising_platform) as total_bank_transfer_amount , count(id) over (partition by fundraising_platform) as total_transfer_cnt , count(case when transfer_mode = 1 then id end) over (partition by fundraising_platform) as total_platformw_transfer_cnt , count(case when transfer_mode = 2 then id end) over (partition by fundraising_platform) as total_bank_transfer_cnt , count(case when org_plat_rk = 1 then ds_org_id end) over (partition by fundraising_platform) as total_transfer_org_cnt , count(case when transfer_mode = 1 and org_plat_mode_rk = 1 then ds_org_id end) over (partition by fundraising_platform) as total_platformw_transfer_org_cnt , count(case when transfer_mode = 2 and org_plat_mode_rk = 1 then ds_org_id end) over (partition by fundraising_platform) as total_bank_transfer_org_cnt , count(case when pid_plat_rk = 1 then ds_project_id end) over (partition by fundraising_platform) as total_transfer_pid_cnt , count(case when transfer_mode = 1 and pid_plat_mode_rk = 1 then ds_project_id end) over (partition by fundraising_platform) as total_platformw_transfer_pid_cnt , count(case when transfer_mode = 2 and pid_plat_mode_rk = 1 then ds_project_id end) over (partition by fundraising_platform) as total_bank_transfer_pid_cnt , count(case when user_plat_rk = 1 then ds_grantee_id end) over (partition by fundraising_platform) as total_transfer_user_cnt , count(case when transfer_mode = 1 and user_plat_mode_rk = 1 then ds_grantee_id end) over (partition by fundraising_platform) as total_platformw_transfer_user_cnt , count(case when transfer_mode = 2 and user_plat_mode_rk = 1 then ds_grantee_id end) over (partition by fundraising_platform) as total_bank_transfer_user_cnt from transfer_data ) a group by fundraising_platform , transfer_date ) t group by fundraising_platform , stat_date