# 从 dim_ds_org_info_d_ql_query_engine_143（机构信息）、dim_ds_project_info_d (HiveSQL)

## Prompt
1) 任务目标
构建数字化工具平台数据日报，按日期+平台维度汇总机构、项目、用户、转账四类指标的累计值和新增值，用于平台运营分析。

2) 输入
- internal_platform_db.dim_ds_org_info_d_ql_query_engine_143：机构信息（分区 imp_date=20260608，is_test_org=0）
- internal_platform_db.dim_ds_project_info_d_ql_query_engine_143：项目信息（分区 imp_date=20260608，is_test_project=0）
- internal_platform_db.dim_ds_grantee_data_d_ql_query_engine_143：受助人数据（分区 imp_date=20260608，ds_grantee_state in (0,1)）
- internal_platform_db.dwd_project_ds_transfer_log_d_ql_query_engine_143：转账流水（分区 imp_date=20260608，transfer_state=2）

3) 处理规则
**平台维度**：fundraising_platform=2 为'慈善平台X'，其他为'其他平台'，同时需产出'所有平台'汇总行
**机构-项目数据 org_pid_data**：
- 机构表 LEFT JOIN 项目表 ON ds_org_id
- 计算机构创建日期（substring(create_time,1,10)）、项目创建日期
- 按机构、项目维度生成各类 row_number，用于首次出现判断
**用户数据 user_data**：
- 受助人表 JOIN 项目表 ON ds_project_id
- 平台W认证日期：取 platformw_auth_time 和 agent_platformw_auth_time 非空者最早日期
- 是否平台W认证：open_id 或 agent_open_id 非空且对应 auth_time 非空
- 是否银行认证：bank_account 非空
- 按机构、项目、用户、代理人、认证维度生成各类 row_number
**转账数据 transfer_data**：
- 转账表 JOIN 项目表 ON ds_project_id
- 转账日期：transfer_mode=1 用 trans_succ_time，否则用 create_time（substring 到日期）
- 按机构、项目、用户、转账方式维度生成各类 row_number
**累计指标计算**：通过窗口函数按平台维度计算累计总数（首次出现即 row_number=1 的实体计数）
**新增指标计算**：按 stat_date 分组统计当日首次出现的实体数量或金额汇总
**聚合方式**：先按各业务日期分组聚合，再 UNION ALL 多个维度（机构创建、项目创建、用户创建、平台W认证、转账）的结果，最后按 fundraising_platform+stat_date 再次聚合取 MAX

4) 输出要求
- 字段顺序：imp_date, fundraising_platform, stat_date, 然后是 52 个指标字段（total_* 26 个，new_* 26 个）
- 52 个指标：机构数/项目机构数/项目数，用户机构数/项目数/用户数/代理人数/平台W认证用户数/银行认证用户数，转账金额/笔数/机构数/项目数/用户数（均分总计/平台W/银行三类）
- imp_date 固定值 20260608
- stat_date 为各业务日期（yyyy-MM-dd），部分行为 NULL（所有平台汇总行）
- fundraising_platform 为'慈善平台X'/'其他平台'/'所有平台'

5) 写入要求
- 目标表：internal_platform_db.ads_gy_digital_tool_used_plat_data_d_ql_cand_query_engine_143
- 写入方式：INSERT INTO
- 输出需包含所有 fundraising_platform 与 stat_date 的组合（含 stat_date 为 NULL 的汇总行）

请将最终 HiveSQL 写入 result.sql 并执行。

## Reference Solution
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