ソースコード
WITH pre AS(
SELECT
    strftime('%Y-%m', SALES_DATE) AS YEAR_MONTH,
    SUM(SALES_AMT) AS MONTH_AMT
--    SUM(SALES_AMT) OVER(ORDER BY strftime('%Y-%m', SALES_DATE) ROWS BETWEEN 11 PRECEDING AND CURRENT ROW) as YEAR_MOVE_AMT
--    SUM(SALES_AMT) OVER(ORDER BY strftime('%Y-%m', SALES_DATE) ASC) AS CUML_AMT
--    SALES_DATE AS YEAR_MONTH
FROM
    SALES
WHERE
--    DATE(SALES_DATE) BETWEEN '2023-01-01' AND '2023-12-31'
--AND
    UPDATED_NO IS NULL
GROUP BY
    strftime('%Y-%m', SALES_DATE)
ORDER BY
    YEAR_MONTH
),
pre2 AS(
SELECT
    YEAR_MONTH,
    MIN(MONTH_AMT) AS MONTH_AMT,
    SUM(MONTH_AMT) FILTER(WHERE YEAR_MONTH BETWEEN '2022-12-01' AND '2023-12-31') OVER(ORDER BY YEAR_MONTH)  AS CUML_AMT,
    SUM(MONTH_AMT) OVER(ORDER BY YEAR_MONTH ROWS 11 PRECEDING) as YEAR_MOVE_AMT
--    SUM(MONTH_AMT) OVER(ORDER BY YEAR_MONTH ROWS BETWEEN 11 PRECEDING AND CURRENT ROW) as YEAR_MOVE_AMT
FROM
    pre
--WHERE
--    YEAR_MONTH BETWEEN '2023-01-01' AND '2023-12-31'
GROUP BY
    YEAR_MONTH
)
SELECT
    YEAR_MONTH,
    MONTH_AMT,
    CUML_AMT,
    YEAR_MOVE_AMT
FROM
    pre2
WHERE
    YEAR_MONTH BETWEEN '2022-12-01' AND '2023-12-31'
提出情報
提出日時2024/02/18 14:21:02
コンテスト第11回 SQLコンテスト
問題Zチャート
受験者north_mb_p
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量85 MB
メッセージ
テストケース(通過数/総数)
2/2
状態
メモリ使用量
データパターン1
AC
84 MB
データパターン2
AC
85 MB