Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我如何使用standardSQL(BigQuery)来区别月份_Sql_Google Bigquery_Bigquery Standard Sql - Fatal编程技术网

我如何使用standardSQL(BigQuery)来区别月份

我如何使用standardSQL(BigQuery)来区别月份,sql,google-bigquery,bigquery-standard-sql,Sql,Google Bigquery,Bigquery Standard Sql,我有以下疑问: #standardSQL SELECT distinct (grand_total/months) AS avg, ((grand_total/days)) AS avg_day FROM (select count(searchint.id) as Total, (DATE_DIFF(DATE ({{DATE_END}}), DATE ({{DATE_START}}), DAY)+1) AS days, ((12 * YEAR(TIMESTAMP({{DATE_END}

我有以下疑问:

#standardSQL
SELECT distinct  (grand_total/months) AS avg, ((grand_total/days)) AS 
avg_day
FROM 
(select count(searchint.id) as Total, (DATE_DIFF(DATE ({{DATE_END}}), 
DATE ({{DATE_START}}), DAY)+1) AS days, ((12 * YEAR(TIMESTAMP({{DATE_END}})) + 
MONTH(TIMESTAMP({{DATE_END}}))) - (12 * YEAR(TIMESTAMP({{DATE_START}})) 
+ MONTH(TIMESTAMP({{DATE_START}}))) +1) AS months,
(select count(searchint.id) as Total
from `dbsearch`
where  cast(replace(searchint.createdDate,'Z','')as DateTime) >= 
cast({{DATE_START}} as DateTime)
and  cast(replace(searchint.createdDate,'Z','')as DateTime) <= 
cast(DATE_ADD(cast({{DATE_END}} as date),  Interval 1 day ) as DateTime)) AS grand_total
    from `dbsearch`
where  cast(replace(searchint.createdDate,'Z','')as DateTime) >= 
cast({{DATE_START}} as DateTime)
and  cast(replace(searchint.createdDate,'Z','')as DateTime) <= 
cast(DATE_ADD(cast({{DATE_END}} as date),  Interval 1 day ) as DateTime)
group by date(cast(replace(searchint.createdDate,'Z','')as DateTime))
ORDER BY 2 DESC) AS groupby
但是,当我尝试运行BigQuery时,会出现以下错误:

未找到函数:年份在[5:180]


我知道这是因为我使用的是standardSQL,但是我如何才能使它与使用standardSQL的月份有所不同呢?

BigQuery中的standardSQL支持用于提取日期部分的ISO/ANSI标准函数。这是摘录:

你想要:

extract(year from <datecol>)
extract(month from <datecol>)

BigQuery中的标准SQL支持用于提取日期部分的ISO/ANSI标准函数。这是摘录:

你想要:

extract(year from <datecol>)
extract(month from <datecol>)

这在。

中进行了解释,以找出两个日期之间的月份差异,您最好使用


要找出两个日期之间的月份差异,最好使用