Google bigquery 大查询-日期比较

Google bigquery 大查询-日期比较,google-bigquery,Google Bigquery,我试图从我在BigQuery中创建的表中检索,该表有许多列,其中一列是Date 类型是DATE,我只想检索两个日期之间的记录 请看下面我的代码 SELECT ExpakAccounts.Account As Account1, ExpakAccounts.description As Name, collection.Col_Dpt As Col_Dpt, collection.Own_Dpt As Own_Dpt, collection.Service As Service, COUNT(co

我试图从我在BigQuery中创建的表中检索,该表有许多列,其中一列是Date

类型是DATE,我只想检索两个日期之间的记录

请看下面我的代码

SELECT ExpakAccounts.Account As Account1, ExpakAccounts.description As Name, collection.Col_Dpt As Col_Dpt, collection.Own_Dpt As Own_Dpt, collection.Service As Service, COUNT(collection.Parcels) AS Cons, SUM(collection.Amount) AS Amount, collection.Filename As Filename, collection.Date AS Date 
FROM `rawdataset.ExPakAccounts2` AS ExpakAccounts 
INNER JOIN `rawdataset.collection_2018` AS Collection ON ExpakAccounts.Account = collection.Account
WHERE ExpakAccounts.Account = collection.Account AND collection.Cat = 100 AND (Col_Dpt <> Own_Dpt) AND (collection.Service = 32 OR collection.Service = 68) AND (DATE(Date) >= '2018-07-30' AND DATE(Date) <= '2018-08-06')
GROUP BY Account1, Name, Col_Dpt, Own_Dpt, Service, Cat, Filename, Date;
选择ExpakAccounts.accounts作为Account1,ExpakAccounts.description作为名称,collection.Col\u Dpt作为Col\u Dpt,collection.Own\u Dpt作为Own\u Dpt,collection.Service作为服务,COUNT(collection.Parcels)作为Cons,SUM(collection.Amount)作为金额,collection.Filename作为文件名,collection.Date作为日期
从'rawdataset.ExPakAccounts2'作为ExpakAccounts
内部联接`rawdataset.collection_2018`作为ExpakAccounts.Account=collection.Account上的集合

其中ExpakAccounts.Account=collection.Account AND collection.Cat=100 AND(Col\u Dpt Own\u Dpt)AND(collection.Service=32或collection.Service=68)AND(DATE(DATE)>='2018-07-30'和DATE(DATE)您可以在
WHERE
子句中使用
日期介于“2018-07-30”和“2018-08-06”之间。这将返回日期介于2018-07-30和2018-08-06之间的行

另外,如果您的字段
Date
已经是
Date
类型,那么使用
Date(Date)
将抛出以下错误
参数类型的函数日期没有匹配的签名:Date。支持的签名:Date(TIMESTAMP,[STRING]);Date Date(DATETIME);Date(INT64,INT64,INT64)
因为函数日期只支持
时间戳
整数

相反,您只需在where子句中按原样使用
Date
字段(没有
Date
函数)

如果您的
Date
字段为string类型,您可以在
WHERE
子句中使用'2018-07-30'和'2018-08-06
之间的
CAST(日期为日期)


有关BigQuery中标准SQL函数的详细信息

错误消息参数类型的函数日期没有匹配签名:日期。