如何仅使用日期字段计算唯一的每日和每周启动日期?

时间:2019-06-11 17:06:17

标签: sql google-bigquery

很抱歉,如果措辞不佳

我需要计算一周中每天启动的网站数量。我目前只有某天发射的东西-可以算作1次发射,并且需要在星期几使用。

我正在使用bigquery,因此必须使用我刚接触过的提取功能。

SELECT
count(Distinct PUBLISHED_DAY),
EXTRACT(DAY from PUBLISHED_DAY) as dow
EXTRACT(WEEK(SUNDAY) from PUBLISHED_DAY) as sunday
EXTRACT(WEEK(MONDAY from PUBLISHED_DAY) as monday
EXTRACT(WEEK(TUESDAY) from PUBLISHED_DAY) as tuesday
EXTRACT(WEEK(WEDNESDAY) from PUBLISHED_DAY) as WEDNESDAY 
EXTRACT(WEEK(THURSDAY) from PUBLISHED_DAY) as THURSDAY
EXTRACT(WEEK(FRIDAY) from PUBLISHED_DAY) as FRIDAY
EXTRACT(WEEK(SATURDAY) from PUBLISHED_DAY) as Saturday 
FROM[table] 

我遇到此错误,我也不知道这会返回按星期几计算的不同天数。  错误:在第3行第13列的“”处遇到了““ FROM”“,原为:”)“ ...

3 个答案:

答案 0 :(得分:0)

您在寻找这个吗?

SELECT EXTRACT(DAYOFWEEK FROM PUBLISHED_DAY) as dow, COUNT(*)
FROM t
GROUP BY dow;

答案 1 :(得分:0)

  

我正在使用bigquery,所以我必须使用我刚接触过的提取功能。

EXTRACT函数在BigQuery Standard SQL(而不是Legacy SQL)中可用,该函数解释了在Legacy SQL中运行时看到的错误

因此,只需确保您是在Standard SQL中进行查询,例如

#standardSQL
SELECT
  EXTRACT(DAYOFWEEK FROM PUBLISHED_DAY) AS dow,
  .... 
FROM `project.dataset.table`   

答案 2 :(得分:0)

考虑使用FORMAT_DATE('%A', PUBLISHED_DAY)代替提取。