ソースコード
with tmp_tbl_2 as 
(
select * 
, lag(process_id, 1) over(partition by session_id order by ex_timestamp) as previous_process
from process_log 
)
,tmp_tbl_3 as 
(
select *
-- 
, case when (process_id = 'STEP1' and previous_process is null 
          or process_id = 'STEP2' and previous_process = 'STEP1'
          or process_id = 'STEP3' and previous_process = 'STEP2'
          or process_id = 'STEP4' and previous_process = 'STEP3'
          or process_id = 'STEP5' and previous_process = 'STEP4'
          ) then 'ok' 
          else 'bad' 
        end as check_
from tmp_tbl_2 
) --step1以外のstepは1つ前のstepが実行されている
,tmp_tbl_4 as (
select *
  ,sum(case when check_ = 'bad' then 1 else 0 end) over(partition by session_id order by ex_timestamp) as cum_bad
from tmp_tbl_3
)
,tmp_tbl_5 as (
select * 
from tmp_tbl_4 
where cum_bad = 0
)
select 
  process_id as PROCESS 
  ,count(session_id) as CNT
from tmp_tbl_5
group by 1 
order by process
;
提出情報
提出日時2023/12/18 15:37:59
コンテスト第10回 SQLコンテスト
問題顧客行動分析
受験者hattsuriboy
状態 (詳細)WA
(Wrong Answer: 誤答)
メモリ使用量85 MB
メッセージ
テストケース(通過数/総数)
3/4
状態
メモリ使用量
データパターン1
AC
85 MB
データパターン2
AC
83 MB
データパターン3
AC
84 MB
データパターン4
WA
84 MB