ソースコード
WITH ranked_checkups AS (
    SELECT 
        CHECKUP_DATE,
        MEMBER_CODE,
        WEIGHT,
        ROW_NUMBER() OVER (PARTITION BY MEMBER_CODE ORDER BY CHECKUP_DATE DESC) AS rn
    FROM 
        HEALTH_CHECKUP
),
weight_changes AS (
    SELECT 
        c1.MEMBER_CODE,
        c1.CHECKUP_DATE AS LATEST_DATE,
        c1.WEIGHT AS LATEST_WEIGHT,
        c2.WEIGHT AS PREVIOUS_WEIGHT,
        ROUND(CAST((c1.WEIGHT - c2.WEIGHT) AS NUMERIC), 1) AS WEIGHT_CHANGE
    FROM 
        ranked_checkups c1
    JOIN 
        ranked_checkups c2 ON c1.MEMBER_CODE = c2.MEMBER_CODE AND c1.rn = 1 AND c2.rn = 2
    WHERE 
        ABS(c1.WEIGHT - c2.WEIGHT) >= 5
)
SELECT 
    wc.LATEST_DATE AS CK_DATE,
    wc.MEMBER_CODE AS CODE,
    m.LAST_NAME || m.FIRST_NAME AS NAME,
    CASE 
        WHEN wc.WEIGHT_CHANGE = ROUND(wc.WEIGHT_CHANGE) THEN CAST(wc.WEIGHT_CHANGE AS INTEGER)
        ELSE wc.WEIGHT_CHANGE
    END AS CHG_WT
FROM 
    weight_changes wc
JOIN 
    MEMBER_MST m ON wc.MEMBER_CODE = m.MEMBER_CODE
ORDER BY 
    ABS(wc.WEIGHT_CHANGE) DESC,
    wc.MEMBER_CODE DESC;
提出情報
提出日時2024/09/28 15:29:45
コンテスト第13回 SQLコンテスト
問題体重差分
受験者cojicoji
状態 (詳細)WA
(Wrong Answer: 誤答)
メモリ使用量96 MB
メッセージ
テストケース(通過数/総数)
0/2
状態
メモリ使用量
データパターン1
WA
96 MB
データパターン2
WA
91 MB