【问题标题】:Add five hours to timestamp field将五个小时添加到时间戳字段
【发布时间】:2016-08-08 20:22:10
【问题描述】:

我想添加几个小时,例如:5 小时 30 分钟到使用 bigquery 的时间戳字段。我的时间戳字段格式为 - '2016-05-03 21:35:03'

如何在 bigquery 中执行此操作?

【问题讨论】:

    标签: google-bigquery


    【解决方案1】:

    为了完整起见,等效的 standard SQL 查询(取消选中“显示选项”下的“使用旧版 SQL”)将是:

    WITH T AS (
      SELECT ts
      FROM UNNEST([CURRENT_TIMESTAMP(),
                   TIMESTAMP("2016-05-03 21:35:03")]) AS ts)
    SELECT TIMESTAMP_ADD(ts, INTERVAL 330 MINUTE) AS ts_plus_530
    FROM T;
    +---------------------+
    |     ts_plus_530     |
    +---------------------+
    | 2016-08-09 04:18:05 |
    | 2016-05-04 03:05:03 |
    +---------------------+
    

    TIMESTAMP_ADD 的文档在这里:https://cloud.google.com/bigquery/sql-reference/functions-and-operators#timestamp_add

    【讨论】:

      【解决方案2】:
      SELECT 
        ts, 
        DATE_ADD(ts, 330, "MINUTE") AS ts_plus_530 
      FROM 
        (SELECT CURRENT_TIMESTAMP() AS ts),
        (SELECT TIMESTAMP("2016-05-03 21:35:03") AS ts)
      

      详情请见DATE_ADD

      【讨论】:

      • 这仅适用于旧版 SQL - 请参阅 @Ellot Brossard 对标准 SQL 解决方案的回答
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-11-10
      • 2017-12-18
      • 1970-01-01
      • 1970-01-01
      • 2017-10-22
      • 1970-01-01
      • 2019-04-30
      相关资源
      最近更新 更多