ソースコード

WITH main AS 
(SELECT
 SUBMISSIONS.*,ENTRIES.STARTED_AT
FROM
 SUBMISSIONS
LEFT JOIN
 (SELECT USER_ID,STARTED_AT FROM ENTRIES WHERE CONTEST_ID = 2) AS ENTRIES
USING
 (USER_ID)
WHERE
 STATUS = 'AC'
AND
 CONTEST_ID = 2
AND
--エントリー外の集計を消す
 ENTRY_ID IS NOT NULL
),
--ユーザ-毎の誤回答数をカウント
wrong_ans AS
(
 SELECT
  S.USER_ID,
  COUNT(SUBMIT_ID) AS WRONG_ANS
 FROM
  SUBMISSIONS AS S
 INNER JOIN
 ( 
  SELECT
   USER_ID,
   PROBLEM_ID,
   MAX(SUBMITTED_AT) AS LAST_SUBMITTED_AT
  FROM
   SUBMISSIONS
  WHERE
   STATUS = 'AC'
  AND
   ENTRY_ID IS NOT NULL
  AND
   CONTEST_ID = 2
  GROUP BY
   USER_ID,PROBLEM_Id
  ) AS SUB1
 ON
  S.USER_ID = SUB1.USER_ID
 AND
  S.PROBLEM_ID = SUB1.PROBLEM_Id
 AND
  S.SUBMITTED_AT < SUB1.LAST_SUBMITTED_AT
 GROUP BY
  S.USER_ID
)

SELECT
 --ランク付けは以下の条件で行っている
 --ポイント高い順
 --回答時間短い順
 --誤回答少ない順
 RANK()OVER(ORDER BY SUM(POINT) DESC,
 strftime('%s',MAX(main.SUBMITTED_AT)) - strftime('%s',MIN(STARTED_AT)) + (IFNULL(MAX(WRONG_ANS),0) * 300)
 ,IFNULL(MAX(WRONG_ANS),0)) AS RANK,
 USER_ID,
 SUM(POINT) AS POINT,
 strftime('%s',MAX(main.SUBMITTED_AT)) - strftime('%s',MIN(STARTED_AT)) + (IFNULL(MAX(WRONG_ANS),0) * 300) AS EX_TIME,
 IFNULL(MAX(WRONG_ANS),0) AS WRONG_ANS
FROM
 main
LEFT JOIN
 wrong_ans
USING
 (USER_ID)
GROUP BY
 USER_ID
HAVING
 SUM(POINT) <> 0
ORDER BY
 RANK,WRONG_ANS,USER_ID

提出情報
提出日時2024/02/06 14:00:50
コンテスト第3回 SQLコンテスト
問題順位計算
受験者romi0416
状態 (詳細)WA
(Wrong Answer: 誤答)
メモリ使用量85 MB
メッセージ
テストケース(通過数/総数)
1/2
状態
メモリ使用量
データパターン1
AC
84 MB
データパターン2
WA
85 MB