質問編集履歴

1

文章の修正

2019/02/24 09:10

投稿

akm2929
akm2929

スコア12

test CHANGED
File without changes
test CHANGED
@@ -16,378 +16,4 @@
16
16
 
17
17
  N週目という形で、現在まで続くようにクエリを書くにはどうすればいいのでしょう…
18
18
 
19
- ちなみに、DL日毎の1日後、7日後、28日後継続率は以下のように集計しています。
20
-
21
- ```standardsql
22
-
23
-
24
-
25
- with T as (
26
-
27
- select
28
-
29
- user_id
30
-
31
- , date(TIMESTAMP_ADD(timestamp_micros(user_first_touch_timestamp), interval device.time_zone_offset_seconds SECOND)) first_touch_date
32
-
33
- , parse_date("%Y%m%d" , event_date) event_date
34
-
35
- from
36
-
37
- `xxxxxx.xxxx.xxevents_*`
38
-
39
- where (
40
-
41
- _TABLE_SUFFIX BETWEEN "2018-07-06" AND FORMAT_DATE("%Y%m%d", DATE_SUB(CURRENT_DATE(), INTERVAL 1 DAY))
42
-
43
- )
44
-
45
- and
46
-
47
- app_info.install_source = 'iTunes'
48
-
49
- and
50
-
51
- date(TIMESTAMP_ADD(timestamp_micros(user_first_touch_timestamp), interval device.time_zone_offset_seconds SECOND)) > "2018-07-06"
52
-
53
- and
54
-
55
- user_id is not null
56
-
57
- and
58
-
59
- date(TIMESTAMP_ADD(timestamp_micros(user_first_touch_timestamp), interval device.time_zone_offset_seconds SECOND)) < CURRENT_DATE('Asia/Tokyo')
60
-
61
- )
62
-
63
-
64
-
65
- , total as (
66
-
67
- select
68
-
69
- first_touch_date
70
-
71
- , count(distinct(user_id)) DL_count
72
-
73
-
74
-
75
- from (
76
-
77
- select
78
-
79
- user_id
80
-
81
- , min(first_touch_date) first_touch_date
82
-
83
- from
84
-
85
- T
86
-
87
- group by
88
-
89
- user_id
90
-
91
- )
92
-
93
-
94
-
95
- group by
96
-
97
- first_touch_date
98
-
99
- )
100
-
101
-
102
-
103
- -- DLから1日後に起動しているユーザーのidを抽出したビュー
104
-
105
- , d1_view as (
106
-
107
- select
108
-
109
- user_id
110
-
111
- , min(first_touch_date) first_touch_date
112
-
113
- from
114
-
115
- T
116
-
117
- group by
118
-
119
- user_id
120
-
121
- , event_date
122
-
123
- having
124
-
125
- date_diff(event_date, first_touch_date, DAY) = 1
126
-
127
- )
128
-
129
-
130
-
131
- -- DL日毎に、DLから1日後に起動しているUU数を抽出したビュー
132
-
133
- , d1_users_count as (
134
-
135
- select
136
-
137
- first_touch_date
138
-
139
- , count(user_id) d1_count
140
-
141
- from
142
-
143
- d1_view
144
-
145
- group by
146
-
147
- first_touch_date
148
-
149
- )
150
-
151
-
152
-
153
- -- DL日
154
-
155
- , d1 as (
156
-
157
- select
158
-
159
- total.first_touch_date -- DL日
160
-
161
- , DL_count -- DL数
162
-
163
- -- D1RR (=DLから1日後に起動していたユーザー数 ÷ DL数)
164
-
165
- , d1_count / DL_count * 100 d1_ratio
166
-
167
- from
168
-
169
- total
170
-
171
- left join
172
-
173
- d1_users_count
174
-
175
- on
176
-
177
- total.first_touch_date = d1_users_count.first_touch_date
178
-
179
- )
180
-
181
-
182
-
183
- -- DLから7日後に起動しているユーザーのidを抽出したビュー
184
-
185
- , d7_view as (
186
-
187
- select
188
-
189
- user_id
190
-
191
- , min(first_touch_date) first_touch_date
192
-
193
- from
194
-
195
- T
196
-
197
- group by
198
-
199
- user_id
200
-
201
- , event_date
202
-
203
- having
204
-
205
- date_diff(event_date, first_touch_date, DAY) = 7
206
-
207
- )
208
-
209
-
210
-
211
- -- DL日毎に、DLから7日後に起動しているUU数を抽出したビュー
212
-
213
- , d7_users_count as (
214
-
215
- select
216
-
217
- first_touch_date
218
-
219
- , count(user_id) d7_count
220
-
221
- from
222
-
223
- d7_view
224
-
225
- group by
226
-
227
- first_touch_date
228
-
229
- )
230
-
231
-
232
-
233
- -- DL日
234
-
235
- , d7 as (
236
-
237
- select
238
-
239
- total.first_touch_date -- DL日
240
-
241
- , DL_count -- DL数
242
-
243
- -- D7RR (=DLから7日後に起動していたユーザー数 ÷ DL数)
244
-
245
- , d7_count / DL_count * 100 d7_ratio
246
-
247
- from
248
-
249
- total
250
-
251
- left join
252
-
253
- d7_users_count
254
-
255
- on
256
-
257
- total.first_touch_date = d7_users_count.first_touch_date
258
-
259
- )
260
-
261
-
262
-
263
- -- DLから28日後に起動しているユーザーのidを抽出したビュー
264
-
265
- , d28_view as (
266
-
267
- select
268
-
269
- user_id
270
-
271
- , min(first_touch_date) first_touch_date
272
-
273
- from
274
-
275
- T
276
-
277
- group by
278
-
279
- user_id
280
-
281
- , event_date
282
-
283
- having
284
-
285
- date_diff(event_date, first_touch_date, DAY) = 28
286
-
287
- )
288
-
289
-
290
-
291
- -- DL日毎に、DLから28日後に起動しているUU数を抽出したビュー
292
-
293
- , d28_users_count as (
294
-
295
- select
296
-
297
- first_touch_date
298
-
299
- , count(user_id) d28_count
300
-
301
- from
302
-
303
- d28_view
304
-
305
- group by
306
-
307
- first_touch_date
308
-
309
- )
310
-
311
-
312
-
313
- -- DL日
314
-
315
- , d28 as (
316
-
317
- select
318
-
319
- total.first_touch_date -- DL日
320
-
321
- , DL_count -- DL数
322
-
323
- -- D28RR (=DLから28日後に起動していたユーザー数 ÷ DL数)
324
-
325
- , d28_count / DL_count * 100 d28_ratio
326
-
327
- from
328
-
329
- total
330
-
331
- left join
332
-
333
- d28_users_count
334
-
335
- on
336
-
337
- total.first_touch_date = d28_users_count.first_touch_date
338
-
339
- )
340
-
341
-
342
-
343
- , Budget as (
344
-
345
- select
346
-
347
- 21.30 d1
348
-
349
- , 7.74 d7
350
-
351
- , 4.18 d28
352
-
353
- )
354
-
355
-
356
-
357
- select
358
-
359
- format_date("%x (%a)", d1.first_touch_date) as first_touch_date
360
-
361
- , d1.d1_ratio
362
-
363
- , d7.d7_ratio
364
-
365
- , d28.d28_ratio
366
-
367
- , Budget.d1
368
-
369
- , Budget.d7
370
-
371
- , Budget.d28
372
-
373
-
374
-
375
- from
376
-
377
- d1, d7, d28, Budget
378
-
379
- where
380
-
381
- d1.first_touch_date = d7.first_touch_date
382
-
383
- and
384
-
385
- d1.first_touch_date = d28.first_touch_date
386
-
387
-
388
-
389
- ```
390
-
391
- ご助言いただければ嬉しいです。
19
+ ご助言いただければいです。
392
-
393
- よろしくお願いします。