これはあなたが必要な情報のみの場合:あなたは、各バーストにいくつかの追加情報を収集する必要があります場合は
select user
,time_
from (select user
,time_
,case when time_ - lag (time_,1,time_-60) over (partition by user order by time_) >= 60 then 'Y' else null end as burst
from my_table
) t
where burst = 'Y'
;
user time_
0 10
0 83
2 12
:
select user
,burst_seq
,min (time_) as min_time_
,max (time_) as max_time_
,count (*) as events_num
from (select user
,time_
,count(burst) over
(
partition by user
order by time_
rows unbounded preceding
) + 1 as burst_seq
from (select user
,time_
,case when time_ - lag (time_) over (partition by user order by time_) >= 60 then 'Y' else null end as burst
from my_table
) t
) t
group by user
,burst_seq
;
user burst_seq min_time_ max_time_ events_num
0 1 10 12 3
0 2 83 85 3
2 1 12 15 3
p.s. CASE文にバグがあるようです。
case when ... then 'Y' end
結果はFAILED:IndexOutOfBoundsExceptionインデックス:2、サイズ:2ですが、これは正当な構文です。
を追加すると、else null
が解決されます。
サンプルテーブルのデータと予想される結果(書式付きテキストも含む)を追加します。 – jarlh
"バースト"の定義は何ですか?あなたは固定されたウィンドウの長さを使用できますか、それとももっと複雑ですか? – Dai
バーストは、すべて同じ時間内に同じユーザーが一緒に発生する多数のイベントです。私はいくつかの例のデータを今追加します –