gpt4 book ai didi

google-bigquery - BigQuery 其中日期小于或等于 3 天减去当前日期

转载 作者:行者123 更新时间:2023-12-04 10:35:00 26 4
gpt4 key购买 nike

我正在尝试创建一个查询以仅返回日期为当前日期减 3 天的数据。我试过了:
date <= DATE_ADD(CURRENT_DATE(), -3, 'DAY')
但这会返回 Error: Expected INTERVAL expression

最佳答案

请参阅以下示例中的 WHERE 子句

#standardSQL
WITH yourTable AS (
SELECT i, date
FROM UNNEST(GENERATE_DATE_ARRAY('2017-04-15', '2017-04-28')) AS date WITH OFFSET AS i
)
SELECT *
FROM yourTable
WHERE date <= DATE_SUB(CURRENT_DATE(), INTERVAL 3 DAY)
-- ORDER BY date

顺便说一句,如果您仍然使用旧版 SQL - 请参见下面的示例

#legacySQL
SELECT *
FROM -- yourTable
(SELECT 1 AS id, DATE('2017-04-20') AS date),
(SELECT 2 AS id, DATE('2017-04-21') AS date),
(SELECT 3 AS id, DATE('2017-04-22') AS date),
(SELECT 4 AS id, DATE('2017-04-23') AS date),
(SELECT 5 AS id, DATE('2017-04-24') AS date),
(SELECT 6 AS id, DATE('2017-04-25') AS date)
WHERE TIMESTAMP(date) <= DATE_ADD(TIMESTAMP(CURRENT_DATE()), -3, 'DAY')
-- ORDER BY date

关于google-bigquery - BigQuery 其中日期小于或等于 3 天减去当前日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43599409/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com