ソースコード
WITH EXISTING_MRR AS (
    SELECT
        MONTHLY
        , SUM(EXISTING_LAG_CALC.LAG_CALC) OVER(
            ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
            ) AS MRR
    FROM
        (
        SELECT
            MONTHLY
            , IFNULL(
                LAG(NEW_MRR, 1) OVER()
                + LAG(EXPANSION_MRR, 1) OVER()
                - LAG(DOWNGRADE_MRR, 1) OVER()
                - LAG(CHURN_MRR, 1) OVER()
                , 0)
                AS LAG_CALC
        FROM
            MRR_DATA
        )
        AS EXISTING_LAG_CALC
)
, NEXT_MONTH_MRR AS (
    SELECT
        DATE(MAX(MD.MONTHLY), '+1 months') AS MONTHLY
        , EM.MRR + MD.NEW_MRR + MD.EXPANSION_MRR - MD.DOWNGRADE_MRR - MD.CHURN_MRR
            AS MRR
    FROM
        MRR_DATA AS MD
    INNER JOIN
        EXISTING_MRR AS EM ON MD.MONTHLY = EM.MONTHLY
)
SELECT 
    MONTHLY AS YM
    , MRR
FROM
    EXISTING_MRR

UNION ALL
SELECT 
    MONTHLY AS YM
    , MRR
FROM
    NEXT_MONTH_MRR
;
提出情報
提出日時2024/01/29 11:41:04
コンテスト第5回 SQLコンテスト
問題MRRの集計
受験者maori
状態 (詳細)WA
(Wrong Answer: 誤答)
メモリ使用量85 MB
メッセージ
テストケース(通過数/総数)
2/3
状態
メモリ使用量
データパターン1
AC
84 MB
データパターン2
AC
85 MB
データパターン3
WA
84 MB