ソースコード
WITH monthly AS(
    SELECT
        strftime('%Y-%m', SALES_DATE) AS monthly,
        sum(SALES_AMT) AS sum_sales
    FROM
        SALES
    WHERE
        UPDATED_NO IS NULL
        AND SALES_DATE > '2022-12-31'
    GROUP BY
        monthly
),
acc AS (
    SELECT
        m1.monthly,
        sum(m2.sum_sales) AS acc
    FROM
        monthly m1
        INNER JOIN monthly m2 ON m1.monthly >= m2.monthly
    GROUP BY
        m1.monthly,
        m1.sum_sales
    ORDER BY
        m1.monthly
),
temp AS(
    SELECT
        strftime('%Y-%m', SALES_DATE) AS monthly,
        SUM(SALES_AMT) AS sales
    FROM
        SALES
    WHERE
        UPDATED_NO IS NULL
    GROUP BY
        monthly
),
mv AS(
    SELECT
        monthly,
        sum(sales) over(
            ORDER BY
                monthly ROWS BETWEEN 11 preceding
                AND current ROW
        ) sum_sales
    FROM
        temp
),
cur AS(
    SELECT
        *
    FROM
        mv
    WHERE
        monthly > '2022-12'
)
SELECT
    monthly.monthly AS YEAR_MONTH,
    monthly.sum_sales AS MONTH_AMT,
    acc.acc AS CUML_AMT,
    cur.sum_sales AS YEAR_MOVE_AMT
FROM
    monthly
    INNER JOIN acc ON monthly.monthly = acc.monthly
    INNER JOIN cur ON monthly.monthly = cur.monthly
ORDER BY
    monthly.monthly
提出情報
提出日時2024/02/19 11:44:02
コンテスト第11回 SQLコンテスト
問題Zチャート
受験者asd
状態 (詳細)WA
(Wrong Answer: 誤答)
メモリ使用量101 MB
メッセージ
テストケース(通過数/総数)
1/2
状態
メモリ使用量
データパターン1
AC
89 MB
データパターン2
WA
101 MB