Last active
April 15, 2021 12:16
-
-
Save mono0926/3775a5a60ef5d8ebbcd325d7a33ee0a4 to your computer and use it in GitHub Desktop.
Firebase AnalyticsのBigQueryから、それぞれのユーザーの直近1ヶ月の最終アクティブ時刻を抽出
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE TEMPORARY FUNCTION | |
today() AS ( ( | |
SELECT | |
CURRENT_DATE('Asia/Tokyo')) ); | |
CREATE TEMPORARY FUNCTION | |
formatDate(d DATE) AS ( ( | |
SELECT | |
FORMAT_DATE('%Y%m%d',d)) ); | |
SELECT | |
user_id as userId, | |
TIMESTAMP_MICROS(MAX(event_timestamp)) AS timestamp | |
FROM | |
`YOUR_PROJECT.YOUR_NEW_FORMAT_DATASET.events_*`, | |
WHERE | |
_TABLE_SUFFIX BETWEEN formatDate(DATE_ADD(today(), INTERVAL -1 MONTH)) | |
AND formatDate(DATE_ADD(today(), INTERVAL -1 DAY)) | |
AND user_id IS NOT NULL | |
GROUP BY | |
user_id | |
ORDER BY | |
timestamp DESC |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment