ソースコード
with r as (
select *
, rank() over(partition by session_id order by EX_TIMESTAMP) as ra
-- , (select count(1) from process_log p2 where process_log.SESSION_ID = p2.SESSION_ID and p2.EX_TIMESTAMP < process_log.EX_TIMESTAMP) as pcnt
from process_log
)
, r2 as (
select * from r where ra = cast(substr(process_id, 5) as integer)
)
, r3 as (
select *, rank() over(partition by session_id order by EX_TIMESTAMP) as ra2
from r2
)
, r4 as (
select process_id, count(1) as CNT from r3 where ra = ra2 group by process_id
)
, ss as (
select 'STEP1' as PROCESS union all
select 'STEP2' union all
select 'STEP3' union all
select 'STEP4' union all
select 'STEP5'
)
select 
ss.PROCESS as PROCESS
, ifnull(r4.CNT, 0) as CNT
from ss left join r4 on ss.process = r4.process_id
order by PROCESS

-- , r2 as (
-- select * from r
-- where ra == cast(substr(process_id, 5) as integer)
-- )
-- , r3 as (select * 
-- , (select count(1) from r2 b where b.ra < a.ra and b.session_id = a.session_id) as cnt
-- from r2 as a
-- )
-- , ss as (
-- select 'STEP1' as PROCESS union all
-- select 'STEP2' union all
-- select 'STEP3' union all
-- select 'STEP4' union all
-- select 'STEP5'
-- )
-- select 
-- ss.PROCESS as PROCESS
-- , ifnull(count(1), 0) as CNT
-- from ss left join r3 on ss.PROCESS = r3.process_id
-- where ra - 1 = cnt
-- group by process_id
-- order by PROCESS
提出情報
提出日時2024/05/03 21:48:15
コンテスト第10回 SQLコンテスト
問題顧客行動分析
受験者daku10
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量85 MB
メッセージ
テストケース(通過数/総数)
4/4
状態
メモリ使用量
データパターン1
AC
83 MB
データパターン2
AC
84 MB
データパターン3
AC
85 MB
データパターン4
AC
84 MB