黑斑羚推拉窗

时间:2017-08-03 10:11:47

标签: sql impala moving-average sliding-window sql-timestamp

我想在impala中运行一个滑动窗口函数,根据5分钟的间隔找到最高价格

换句话说,我想比较当前行的价格与过去5分钟内的所有行并写出最高价格

分析函数通常以行号为界,它们是否也可以按日期限制?

ID,     Timestamp,          price
1,  2015-04-07 15:43:02,    230
2,  2015-04-07 15:44:04,    205
3,  2015-04-07 15:46:11,    220
4,  2015-04-07 15:48:02,    210
5,  2015-04-07 15:52:09,    200
6,  2015-04-07 15:53:32,    220
7,  2015-04-07 15:54:12,    207
8,  2015-04-07 15:57:33,    218
9,  2015-04-07 15:61:26,    221
10, 2015-04-07 15:61:01,    210

预期产出:

ID,     Timestamp,          price, Max(price)
1,  2015-04-07 15:43:02,    230     230
2,  2015-04-07 15:44:04,    205     230
3,  2015-04-07 15:46:11,    220     230
4,  2015-04-07 15:48:01,    210     230
5,  2015-04-07 15:52:09,    200     210
6,  2015-04-07 15:53:32,    220     220
7,  2015-04-07 15:54:12,    207     220
8,  2015-04-07 15:57:33,    218     220
9,  2015-04-07 16:01:26,    221     221
10, 2015-04-07 16:07:51,    210     210

0 个答案:

没有答案