ソースコード
with tmp0 as (
    select
        session_id,
        process_id,
        lag(process_id, 1) over (
            partition by session_id
            order by ex_timestamp asc
        ) as prev_process_id,
        ex_timestamp
    from process_log
),
tmp1 as (
    select
        session_id,
        process_id,
        case
            when process_id = 'STEP1' and prev_process_id is null 
                or cast(substr(process_id, 5, 1) as integer) = cast(substr(prev_process_id, 5, 1) as integer) + 1
            then 1
            else 0
        end as valid_process,
        ex_timestamp
    from tmp0
),
tmp2 as (
    select
        session_id,
        process_id,
        min(valid_process) over (
            partition by session_id
            order by ex_timestamp asc
        ) as min_valid_process
    from tmp1
)
select
    process_id as PROCESS,
    count(case when min_valid_process = 1 then session_id end) as CNT
from tmp2
group by process_id
order by process_id asc
提出情報
提出日時2023/12/19 22:01:37
コンテスト第10回 SQLコンテスト
問題顧客行動分析
受験者toshikish
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量87 MB
メッセージ
テストケース(通過数/総数)
4/4
状態
メモリ使用量
データパターン1
AC
84 MB
データパターン2
AC
87 MB
データパターン3
AC
86 MB
データパターン4
AC
85 MB