與一個邏輯窗口分析功能可以直接提供這樣的信息:
select l.tmstmp,
count(*) over (order by tmstmp range between current row and interval '59.999999' second following) cnt
from log_table l
order by 1
;
TMSTMP CNT
--------------------------- ----------
01.01.16 00:00:00,000000000 4
01.01.16 00:00:10,000000000 4
01.01.16 00:00:15,000000000 3
01.01.16 00:00:20,000000000 2
01.01.16 00:01:00,000000000 3
01.01.16 00:01:40,000000000 2
01.01.16 00:01:50,000000000 1
請調整您的精度的區間長度。它必須是低於1分鐘的最高可能值。
爲了獲得最大分鐘使用子查詢(不要忘記,你可能會收到更多的一個記錄 - 用MAX計數):
with tst as (
select l.tmstmp,
count(*) over (order by tmstmp range between current row and interval '59.999999' second following) cnt
from log_table l)
select * from tst where cnt = (select max(cnt) from tst);
TMSTMP CNT
--------------------------- ----------
01.01.16 00:00:00,000000000 4
01.01.16 00:00:10,000000000 4
有你已經選中了這個問題? http://stackoverflow.com/questions/14989927/sql-sliding-window-finding-max-value-over-interval我想它也可以適應1分鐘的時間間隔。 –