在自定义查询中查询数据时格式化 event_date 和 event_timestamp 大查询

She*_*een 2 google-analytics google-bigquery firebase-analytics

嗨,以下是我的查询,用于获取大量数据,query想知道我们如何格式化datetime stamp

SELECT
  *
FROM (
  SELECT
    (
    SELECT
      x.value
    FROM
      UNNEST(user_properties) x
    WHERE
      x.key='restaurantName'
      AND x.value IS NOT NULL).string_value AS restaurantName,
    event_date AS date,
    event_timestamp AS time,
    event_name AS Event,
    (
    SELECT
      x.value
    FROM
      UNNEST(user_properties) x
    WHERE
      x.key='restaurantId'
      AND x.value IS NOT NULL).string_value AS restaurantID,
    (
    SELECT
      x.value
    FROM
      UNNEST(user_properties) x
    WHERE
      x.key='user_id'
      AND x.value IS NOT NULL).string_value AS user
  FROM
    `analytics.events_*`
  WHERE
    event_name = "OrderSummary"
    AND app_info.id = "app_Id"
  ORDER BY
    event_timestamp ASC)
WHERE
  NOT(restaurantName IS NULL
    OR restaurantID="someName")
Run Code Online (Sandbox Code Playgroud)

我正在正确过滤数据但无法格式化

在此处输入图片说明

Mik*_*ant 11

您希望在输出中使用的格式?日期 = 28-11-2019 时间 = 04:22:13

下面是 BigQuery 标准 SQL

更改/修复就在两行以下

event_date AS date,
event_timestamp AS time,  
Run Code Online (Sandbox Code Playgroud)

所以,而不是上面 - 在下面使用

FORMAT_DATE('%d-%m-%Y', PARSE_DATE('%Y%m%d', event_date)) AS date, 
FORMAT_TIME('%T', TIME(TIMESTAMP_MICROS(event_timestamp))) time,   
Run Code Online (Sandbox Code Playgroud)

和相应的输出列将像

Row date        time     
1   28-11-2019  04:22:13     
Run Code Online (Sandbox Code Playgroud)

注意:我假设该event_date字段是 STRING 数据类型。如果它实际上是一个 INT64 - 你只需要 ueCAST(event_date AS STRING)而不是event_date


Fel*_*ffa 6

变换为TIMESTAMP,则FORMAT_TIMESTAMP()

WITH data AS (SELECT 1574914933030017 ms)


SELECT TIMESTAMP_MICROS(ms)
  , FORMAT_TIMESTAMP('%d/%m/%Y %H:%M', TIMESTAMP_MICROS(ms))
FROM data


2019-11-28 04:22:13.030017 UTC
28/11/2019 04:22
Run Code Online (Sandbox Code Playgroud)