ソースコード
 WITH AX(n, MONTHLY) AS (
    SELECT
            n, date(MIN_YM, (n - 1) || ' months') AS MONTHLY
        FROM 
            (
                SELECT
                    MIN(MONTHLY) AS MIN_YM
                    , MAX(MONTHLY) AS MAX_YM
                FROM
                    MRR_DATA
            ) MS
            , (
                SELECT
                        ROW_NUMBER() OVER () AS n
                    FROM
                        (VALUES(1),(2),(3),(4),(5),(6)) N1
                        , (VALUES(1),(2),(3),(4),(5),(6)) N2
                        , (VALUES(1),(2),(3),(4),(5),(6)) N3
            ) N
        WHERE
            date(MIN_YM, (n - 1) || ' months') <= date(MAX_YM,'1 months')
    )
    , MDX(n, monthly, DMRR) AS (
        SELECT
            n
            , monthly
            , COALESCE(
                NEW_MRR
                 + EXPANSION_MRR
                 - DOWNGRADE_MRR
                 - CHURN_MRR
             , 0) AS DMRR
        FROM
            AX
            LEFT OUTER JOIN MRR_DATA
            USING (MONTHLY)
    )
    , X(n, monthly, MRR, DMRR) AS (
        SELECT
            n, monthly
            , 0 AS MRR
            , DMRR
        FROM
            MDX
        WHERE
            n = 1
        UNION ALL
            SELECT
                MDX.n, MDX.monthly, X.MRR + X.DMRR, MDX.DMRR
            FROM
                X
                INNER JOIN MDX
                ON X.n + 1 = MDX.n
        )
SELECT
        monthly AS YM
        , MRR
    FROM
        X
    ORDER BY
        monthly

提出情報
提出日時2023/02/20 00:09:41
コンテスト第5回 SQLコンテスト
問題MRRの集計
受験者KAZAMAI_NaruTo
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量80 MB
メッセージ
テストケース(通過数/総数)
3/3
状態
メモリ使用量
データパターン1
AC
79 MB
データパターン2
AC
80 MB
データパターン3
AC
80 MB