ソースコード
with 
-- 必要なデータのみ取り出す
ac as (select *,strftime("%s",SUBMITTED_AT) as t from SUBMISSIONS where CONTEST_ID =2 and STATUS ="AC" and ENTRY_ID is not null)
,wa as (select * from SUBMISSIONS where CONTEST_ID =2 and STATUS ="WA" and ENTRY_ID is not null)
,et as (select *,strftime("%s",STARTED_AT) as t from ENTRIES where  CONTEST_ID =2)
-- 誤回答数
,wacnt as (
select
    wa.ENTRY_ID,
    count() as WRONG_ANS
from
    wa
    inner join
    ac
    on wa.entry_id = ac.entry_id and wa.PROBLEM_ID=ac.PROBLEM_ID
where
    wa.SUBMITTED_AT < ac.SUBMITTED_AT
group by
    wa.USER_ID
)
-- 集計
,base as (
select
    ac.USER_ID 
    ,sum(point) as POINT
    ,max(ac.t) - max(et.t) + coalesce(max(WRONG_ANS),0)*300 as EX_TIME
    ,coalesce(max(WRONG_ANS),0) as WRONG_ANS
from
    ac
    inner join
    et
    on et.ENTRY_ID = ac.ENTRY_ID
    left join
    wacnt
    on ac.ENTRY_ID = wacnt.ENTRY_ID
group by
    ac.ENTRY_ID
)
--ランク付けして出力
select
    rank() over(order by POINT desc,EX_TIME) as `RANK`
    ,USER_ID
    ,POINT
    ,EX_TIME
    ,WRONG_ANS
from
    base
order by
    `RANK`
    ,WRONG_ANS
    ,USER_ID
    
提出情報
提出日時2024/03/08 16:13:52
コンテスト第3回 SQLコンテスト
問題順位計算
受験者gP2fWnUzTL
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量84 MB
メッセージ
テストケース(通過数/総数)
2/2
状態
メモリ使用量
データパターン1
AC
84 MB
データパターン2
AC
84 MB