ソースコード
with
    t as (
        select
            session_id
            ,process_id
            ,ex_timestamp
            ,rank() over (partition by session_id order by ex_timestamp) as ord
            ,cast(substr(process_id, 5, 1) as int) as step
        from
            process_log
        order by
            session_id
    )
    ,u as (
        select
            *
            ,case
                when ord = step then 1
                else 0
                end as flag
        from
            t
    )
    ,w as (
        select
            *
            ,sum(flag) over (partition by session_id order by ord) as judge
        from
            u
    )
    ,v as (
        select
            session_id
            ,process_id
            ,ex_timestamp
            ,max(ord) as reach
        from
            w
        where
            ord = judge
        group by
            1
    )
 
select
    'STEP1' as PROCESS
    ,count(session_id) as CNT
from
    v
where
    reach >= 1
union
select
    'STEP2' as PROCESS
    ,count(session_id) as CNT
from
    v
where
    reach >= 2
union
select
    'STEP3' as PROCESS
    ,count(session_id) as CNT
from
    v
where
    reach >= 3
union
select
    'STEP4' as PROCESS
    ,count(session_id) as CNT
from
    v
where
    reach >= 4
union
select
    'STEP5' as PROCESS
    ,count(session_id) as CNT
from
    v
where
    reach >= 5
提出情報
提出日時2023/12/15 23:25:08
コンテスト第10回 SQLコンテスト
問題顧客行動分析
受験者takahirostone
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量88 MB
メッセージ
テストケース(通過数/総数)
4/4
状態
メモリ使用量
データパターン1
AC
86 MB
データパターン2
AC
88 MB
データパターン3
AC
86 MB
データパターン4
AC
85 MB