ソースコード
--ENTRIEをjoinすれば、SUBMISSIONS内のNULLは消える。

WITH TEMP AS(
    SELECT * FROM ENTRIES NATURAL JOIN SUBMISSIONS
    WHERE CONTEST_ID = 2
)

,LAST_AC_TIME_RANK AS(
    SELECT
        USER_ID
        ,SUBMITTED_AT
        ,RANK() OVER (PARTITION BY USER_ID ORDER BY SUBMITTED_AT DESC) AS AC_RANK
    FROM TEMP
    WHERE STATUS = 'AC'
)

,LAST_AC_TIME AS(
    SELECT
        USER_ID
        ,STARTED_AT
        ,SUBMITTED_AT
        ,STRFTIME('%s', SUBMITTED_AT) - STRFTIME('%s', STARTED_AT) AS AC_TIME
    FROM TEMP NATURAL JOIN LAST_AC_TIME_RANK
    WHERE AC_RANK = 1
)

,LAST_AC_TIME_MAX AS(
    SELECT
        USER_ID
        ,PROBLEM_ID
        ,MAX(SUBMITTED_AT) AS PROB_MAX_AC_TIME
        FROM TEMP
        WHERE STATUS = 'AC'
        GROUP BY USER_ID, PROBLEM_ID
)

,WA_COUNT AS(
    SELECT
        USER_ID
        ,PROBLEM_ID
        ,COUNT(STATUS) AS WA_COUNTS
        FROM TEMP NATURAL JOIN LAST_AC_TIME_MAX
        WHERE STATUS != 'AC'
        GROUP BY USER_ID
        HAVING SUBMITTED_AT < PROB_MAX_AC_TIME
)

,SUM_POINT AS(
    SELECT
        USER_ID
        ,CONTEST_ID
        ,SUM(POINT) AS POINT
    FROM TEMP
    WHERE STATUS = 'AC'
    GROUP BY
        USER_ID
        ,CONTEST_ID
    HAVING SUM(POINT) > 0
)

SELECT
    RANK() OVER (ORDER BY s.POINT DESC, l.AC_TIME + IFNULL(w.WA_COUNTS,0) * 300)AS RANK
    ,l.USER_ID AS USER_ID
    ,s.POINT AS POINT
    ,l.AC_TIME + IFNULL(w.WA_COUNTS,0) * 300 AS EX_TIME
    ,IFNULL(w.WA_COUNTS,0) AS WRONG_ANS
FROM LAST_AC_TIME AS l
LEFT OUTER JOIN WA_COUNT AS w
ON l.USER_ID = w.USER_ID
LEFT OUTER JOIN SUM_POINT AS s
ON l.user_id = s.user_id
WHERE SUM_POINT IS NOT NULL
ORDER BY RANK, WRONG_ANS, L.USER_ID
提出情報
提出日時2023/02/14 16:28:19
コンテスト第3回 SQLコンテスト
問題順位計算
受験者mott
状態 (詳細)RE
(Runtime Error: 実行時エラー)
メモリ使用量76 MB
メッセージ
SQLITE_ERROR: no such column: SUM_POINT
テストケース(通過数/総数)
0/2
状態
メモリ使用量
データパターン1
RE
76 MB
データパターン2
RE
76 MB