简体   繁体   中英

Impala : Running sum of 1 hour

I want to count records of each ID with in 1 Hour. I tried out some IMPALA queries but without any luck.

I have input data as follows:

在此处输入图片说明

And expected output would be:

在此处输入图片说明

I tried :

select
      concat(month,'/',day,'/',year,' ',hour,':',minute) time, id,
     count(1) over(partition by id order by concat(month,'/',day,'/',year,' ',hour,':',minute) range between '1 hour' PRECEDING AND CURRENT ROW) request
       from rt_request
       where
    concat(year,month,day,hour) >= '2019020318' 
group by id, concat(month,'/',day,'/',year,' ',hour,':',minute)

But I got exception.

RANGE is only supported with both the lower and upper bounds UNBOUNDED or one UNBOUNDED and the other CURRENT ROW.

Any suggestion/help would be appreciated. Thank you in advance!

I think you are looking for counts for the same hour across days for a given id. You can simply use row_number to do this.

select time,id,row_number() over(partition by id,hour order by concat(month,'/',day,'/',year,' ',hour,':',minute)) as total
from tbl

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM