BigQuery - 如何比较“日期”列(使用传统SQL)? [英] BigQuery - how to compare a "date" column (using legacy SQL)?
问题描述
我有一个包含 Date
这个 date
类型的BigQuery表。我试图运行这个查询:
$ p $ SELECT * FROM dataset.table_name WHERE Date =2016-07-11
这会引发错误:
函数中的参数类型不匹配EQUAL:'Date'是类型int32,'2016-07-11'是字符串
我也试过这个查询:
SELECT * FROM dataset.table_name WHERE Date = TIMESTAMP (2016-07-11)
但这返回0结果,尽管我的表至少包含在日期
列中一个包含此值( 2016-07-11
)的记录。
那么,如何比较BigQuery中的 date
字段?
在下面尝试
WHERE DATE(日期)=2016-07-11
我的其他建议是不使用保留字作为列名,我认为如果您的列名是d正确 - 您的原始 WHERE
子句可以很好地工作,您不需要使用 DATE()=
I have a BigQuery table with a column Date
which is a date
type. I am trying to run this query:
SELECT * FROM dataset.table_name WHERE Date = "2016-07-11"
This throws the error:
Argument type mismatch in function EQUAL: 'Date' is type int32, '2016-07-11' is type string
I have also tried this query:
SELECT * FROM dataset.table_name WHERE Date = TIMESTAMP("2016-07-11")
but this returns 0 results, although my table contains at least one record with this value (2016-07-11
) in the Date
column.
So, how can I compare a date
field in BigQuery?
Try below
WHERE DATE(Date) = "2016-07-11"
My additional recommendation would be to not to use reserved words as column's name, I think if your column was named properly - your original WHERE
clause would worked perfectly and you would not need to use workaround with DATE()=""
这篇关于BigQuery - 如何比较“日期”列(使用传统SQL)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!