BigQuery SQL WHERE 当前日期和 -15 天之间的日期
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/41243816/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
BigQuery SQL WHERE Date Between Current Date and -15 Days
提问by Eric Hendershott
I am trying to code the following condition in the WHERE
clause of SQL in BigQuery, but I am having difficulty with the syntax, specifically datemath:
我试图WHERE
在 BigQuery 的 SQL 子句中编写以下条件,但我在语法上遇到困难,特别是日期数学:
WHERE date_column between current_date() and current_date() - 15 days
This seems easy in MySQL, but I can't get it to work with BigQuery SQL.
这在 MySQL 中似乎很容易,但我无法让它与 BigQuery SQL 一起使用。
回答by JohnHC
回答by Siyual
You should probably switch the two around - the syntax should be the following:
您可能应该切换两者 - 语法应如下所示:
WHERE date_column BETWEEN DATE_ADD(CURRENT_DATE(), -15, 'DAY') AND CURRENT_DATE()
回答by ppk28
This works for me.
这对我有用。
WHERE DATE(date_column) BETWEEN DATE(DATE_ADD(CURRENT_DATE(), -15, 'DAY'))
AND CURRENT_DATE()
回答by KARTHIKEYAN.A
Use current_date()function
使用current_date()函数
SELECT ARRAY_TO_STRING(split(cast(current_date() as string),"-"),'')