Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/83.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
Sql 为每个小组查找最频繁的日期_Sql_Google Bigquery - Fatal编程技术网

Sql 为每个小组查找最频繁的日期

Sql 为每个小组查找最频繁的日期,sql,google-bigquery,Sql,Google Bigquery,我正在从BigQuery查询奥斯汀犯罪数据集 这是预览: 我想查询总的发病率和他们发生的最频繁的一天,按犯罪类型分组 我的实际查询如下: SELECT description, count(*) as incidences FROM bigquery-public-data.austin_crime.crime group by description order by incidences desc; 但是我找不到一种方法来找出每种类型犯罪的大多数案件的发生日期嗯。一种方法是通过说明和工

我正在从BigQuery查询奥斯汀犯罪数据集

这是预览:

我想查询总的发病率和他们发生的最频繁的一天,按犯罪类型分组

我的实际查询如下:

SELECT description, count(*) as incidences 
FROM bigquery-public-data.austin_crime.crime
group by description
order by incidences desc;

但是我找不到一种方法来找出每种类型犯罪的大多数案件的发生日期

嗯。一种方法是通过
说明
工作日
进行聚合。使用窗口函数确定
说明
上的总数和最高工作日总数:

select description, weekday, weekday_incidences, incidences
from (select description, format_timestamp('%a', timestamp) as weekday,
             ​count(*) as weekday_incidences,
             sum(count(*)) over (partition by description) as incidences,
             row_number() over (partition by description order by count(*) desc) as seqnum
      from `bigquery-public-data.austin_crime.crime` c
      group by description, weekday
     ) c
where seqnum = 1
order by incidences desc;

请提供样本数据和所需输出,并定义“最频繁的一天”是什么。