ソースコード
with wrong as (
    select
        ok.user_id
    ,   count(*) as count
    from
        submissions ok
    inner join
        submissions ng
    on
        ng.contest_id = ok.contest_id
    and ng.problem_id = ok.problem_id
    and ng.user_id = ok.user_id
    and ng.status != 'AC'
    and ng.submitted_at < ok.submitted_at
    and ng.entry_id is not null
    where
        ok.contest_id = 2
    and ok.status = 'AC'
    and ok.entry_id is not null
    group by
        ok.user_id
)
,   success as (
    select
        ok.user_id
    ,   max(strftime('%s', ok.submitted_at) - strftime('%s', e.started_at)) as last_submit
    ,   sum(ok.point) as total
    from
        submissions ok
    inner join
        entries e
    on 
        e.entry_id = ok.entry_id
    where
        ok.contest_id = 2
    and ok.status = 'AC'
    and ok.entry_id is not null
    group by
        ok.user_id
)
select
    rank()over(
        order by 
            s.total desc
        ,   s.last_submit + 300 * coalesce(w.count,0) asc
    )           as RANK
,   s.user_id   as USER_ID
,   s.total     as POINT
,   s.last_submit + 300 * coalesce(w.count,0) as EX_TIME
,   coalesce(w.count,0) as WRONG_ANS
from
    success s
left outer join
    wrong w
on
    w.user_id = s.user_id
where
    s.total > 0
order by
    RANK
提出情報
提出日時2022/10/20 09:03:37
コンテスト第3回 SQLコンテスト
問題順位計算
受験者bubusuke
状態 (詳細)WA
(Wrong Answer: 誤答)
メモリ使用量89 MB
メッセージ
テストケース(通過数/総数)
1/2
状態
メモリ使用量
データパターン1
AC
88 MB
データパターン2
WA
89 MB