Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/67.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_Vertica - Fatal编程技术网

查找每日SQL数据的每周峰值

查找每日SQL数据的每周峰值,sql,vertica,Sql,Vertica,我将数据存储在Vertica sql数据库中,其结构如下: location date count Seattle 2015-09-21 48991 Portland 2015-09-21 38396 Seattle 2015-09-22 49639 Portland 2015-09-22 28817 Portland 2015-09-23 29183 Seattle 2015-09-23 50210 Portland 2015-09-

我将数据存储在Vertica sql数据库中,其结构如下:

location date count
Seattle     2015-09-21  48991
Portland    2015-09-21  38396
Seattle     2015-09-22  49639
Portland    2015-09-22  28817
Portland    2015-09-23  29183
Seattle     2015-09-23  50210
Portland    2015-09-24  29627
Seattle     2015-09-24  50844
Seattle     2015-09-25  56485
Portland    2015-09-25  30076
Portland    2015-09-26  30352
Seattle     2015-09-26  52011
Portland    2015-09-27  30491
Seattle     2015-09-27  52291
计数为每日峰值。我想为每个星期提取最大计数,因此我基本上以每周峰值结束

location week_ending_date count
Portland    2015-09-27  38396
Seattle     2015-09-27  56485   
有什么建议吗


谢谢

假设你的一周从周一开始

SQL> select * from wtest order by dt ;
 location |     dt     | count 
----------+------------+-------
 Seattle  | 2015-09-21 | 48991
 Portland | 2015-09-21 | 38396
 Portland | 2015-09-22 | 28817
 Seattle  | 2015-09-22 | 49639
 Portland | 2015-09-23 | 29183
 Seattle  | 2015-09-23 | 50210
 Portland | 2015-09-24 | 29627
 Seattle  | 2015-09-24 | 50844
 Portland | 2015-09-25 | 30076
 Seattle  | 2015-09-25 | 56485
 Portland | 2015-09-26 | 30352
 Seattle  | 2015-09-26 | 52011
 Portland | 2015-09-27 | 30491
 Seattle  | 2015-09-27 | 52291

SQL> select 
        location, 
        min(dt) + 6 as week_ending_date, 
        max(count) as count 
     from 
        wtest 
     group by location, year_iso(dt), week_iso(dt) ;

 location | week_ending_date | count 
----------+------------------+-------
 Portland | 2015-09-27       | 38396
 Seattle  | 2015-09-27       | 56485

你如何定义一周?从哪一天开始?您可以使用,但无论采用哪种方式,在年底展期时都会出现问题。如果这两个函数都不适合您的需要,最简单的解决方案可能是创建您自己的日历表。请使用您遇到问题的SQL更新您的问题with@BaconBits如果他/她既不能使用
week
(从周日开始)也不能使用
week\u iso
(从周一开始),则
time\u slice()
aggregate函数将完成此任务。。。