File size: 26,703 Bytes
e8c001c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
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