ソースコード
INSERT INTO MRR_DATA VALUES ('2023-01-01', 0, 0, 0, 0);
WITH LAST_MONTH AS(
SELECT
    MONTHLY
    ,CASE 
        WHEN SUM(NEW_MRR + EXPANSION_MRR - DOWNGRADE_MRR - CHURN_MRR) OVER(ORDER BY MONTHLY ROWS BETWEEN 1 PRECEDING AND 1 PRECEDING) IS NULL
        THEN 0
        ELSE SUM(NEW_MRR + EXPANSION_MRR - DOWNGRADE_MRR - CHURN_MRR) OVER(ORDER BY MONTHLY ROWS BETWEEN 1 PRECEDING AND 1 PRECEDING)
    END AS LM_SUM
FROM MRR_DATA
)

,LAST_MONTH_MRR AS(
SELECT
    MONTHLY
    ,SUM(LM_SUM) OVER(ORDER BY MONTHLY ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS LM_MRR
FROM LAST_MONTH
)

SELECT
    MONTHLY AS YM
    ,CASE 
        WHEN SUM(NEW_MRR + EXPANSION_MRR - DOWNGRADE_MRR - CHURN_MRR) OVER(ORDER BY MONTHLY ROWS BETWEEN 1 PRECEDING AND 1 PRECEDING) IS NULL
        THEN 0
        ELSE SUM(NEW_MRR + EXPANSION_MRR - DOWNGRADE_MRR - CHURN_MRR  + LM_MRR) OVER(ORDER BY MONTHLY ROWS BETWEEN 1 PRECEDING AND 1 PRECEDING)
    END AS MRR
FROM MRR_DATA
JOIN LAST_MONTH_MRR USING(MONTHLY)
提出情報
提出日時2023/02/21 09:39:13
コンテスト第5回 SQLコンテスト
問題MRRの集計
受験者mott
状態 (詳細)WA
(Wrong Answer: 誤答)
メモリ使用量76 MB
メッセージ
テストケース(通過数/総数)
0/3
状態
メモリ使用量
データパターン1
WA
76 MB
データパターン2
WA
76 MB
データパターン3
WA
76 MB