BigQuery 时间戳当前日期减去 x 天

问题描述 投票:0回答:2

我有一个 TIMESTAMP 列,其中包含需要过滤的日期。我需要获取 5 天前的数据。所以

current date - 5 days
。我的数据位于 BigQuery 中。我尝试了以下查询:

where created_time >= (TIMESTAMP_TRUNC(CURRENT_TIMESTAMP(), DAY), INTERVAL -5 DAY)

我收到错误:

Unexpected INTERVAL expression

datetime google-bigquery timestamp
2个回答
5
投票

你失踪了

TIMESTAMP_ADD()
:

where created_time > TIMESTAMP_ADD(TIMESTAMP_TRUNC(CURRENT_TIMESTAMP(), DAY), INTERVAL -5 DAY)

0
投票

也可以使用TIMESTAMP_SUB()

where created_time > TIMESTAMP_SUB(TIMESTAMP_TRUNC(CURRENT_TIMESTAMP(), DAY), INTERVAL 5 DAY)
© www.soinside.com 2019 - 2024. All rights reserved.