ソースコード
with T as (
    select
        user_id,
        problem_id,
        point,
        (
            select 
                submitted_at 
            from Submissions s2 
            where s2.user_id = s1.user_id 
            and s2.problem_id = s1.problem_id 
            and status = 'AC' 
            order by submitted_at desc 
            limit 1
        ) first_ac_time
    from Submissions s1
    where contest_id = 2
    group by user_id, problem_id, point
),
T2 as (
    select 
        user_id,
        problem_id,
        (
            case when first_ac_time is null
                then (
                    select 
                        count(*) 
                    from Submissions s 
                    where s.user_id = t.user_id 
                    and s.problem_id = t.problem_id 
                    and status = 'WA'
                )
                else (
                    select 
                        count(*) 
                    from Submissions s 
                    where s.user_id = t.user_id 
                    and s.problem_id = t.problem_id 
                    and status = 'WA'
                    and submitted_at < first_ac_time
                )
            end
        ) wa_count,
        (
            case when first_ac_time is null 
                then 0
                else point
            end
        ) got_point,
        first_ac_time
    from T t
),
T3 as (
    select
        user_id,
        sum(got_point) point,
        sum(wa_count) wrong_ans,
        max(first_ac_time) last_problem_ac_time
    from T2
    group by user_id
    having last_problem_ac_time is not null
),
T4 as (
    select
        user_id,
        unixepoch(last_problem_ac_time) - (
            select 
                unixepoch(started_at)
            from Entries e 
            where e.user_id = t.user_id
            and contest_id = 2
            limit 1
        ) ex_time,
        point,
        wrong_ans
    from T3 t
)
select
    rank() over(order by point desc, ex_time) RANK,
    user_id USER_ID,
    point POINT,
    ex_time EX_TIME,
    wrong_ans WRONG_ANS
from T4
order by RANK, EX_TIME desc
提出情報
提出日時2022/10/20 02:39:12
コンテスト第3回 SQLコンテスト
問題順位計算
受験者jau5
状態 (詳細)WA
(Wrong Answer: 誤答)
メモリ使用量85 MB
メッセージ
テストケース(通過数/総数)
0/2
状態
メモリ使用量
データパターン1
WA
85 MB
データパターン2
WA
81 MB