ソースコード
WITH MonthlyAmount AS (
    SELECT 
        STRFTIME('%Y-%m', SALES_DATE) AS YEAR_MONTH,
        SUM(SALES_AMT) AS MONTH_AMT
    FROM 
        SALES
    WHERE 
        UPDATED_NO IS NULL
    GROUP BY 
        STRFTIME('%Y-%m', SALES_DATE)
),
CumulativeAmount AS (
    SELECT 
        YEAR_MONTH,
        SUM(MONTH_AMT) OVER (ORDER BY YEAR_MONTH) AS CUML_AMT
    FROM 
        MonthlyAmount
    WHERE
        MonthlyAmount.YEAR_MONTH BETWEEN '2023-01' AND '2023-12'
),
YearlyMoveAmount AS (
    SELECT 
        YEAR_MONTH,
        SUM(MONTH_AMT) OVER (ORDER BY YEAR_MONTH ROWS BETWEEN 11 PRECEDING AND CURRENT ROW) AS YEAR_MOVE_AMT
    FROM 
        MonthlyAmount
)
SELECT 
    MonthlyAmount.YEAR_MONTH AS YEAR_MONTH,
    MonthlyAmount.MONTH_AMT AS MONTH_AMT,
    CumulativeAmount.CUML_AMT AS CUML_AMT,
    YearlyMoveAmount.YEAR_MOVE_AMT AS YEAR_MOVE_AMT
FROM 
    MonthlyAmount
JOIN 
    CumulativeAmount ON MonthlyAmount.YEAR_MONTH = CumulativeAmount.YEAR_MONTH
JOIN 
    YearlyMoveAmount ON MonthlyAmount.YEAR_MONTH = YearlyMoveAmount.YEAR_MONTH
WHERE
    MonthlyAmount.YEAR_MONTH BETWEEN '2023-01' AND '2023-12'
ORDER BY
    YEAR_MONTH;
提出情報
提出日時2024/02/17 14:15:12
コンテスト第11回 SQLコンテスト
問題Zチャート
受験者pyh1969
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量85 MB
メッセージ
テストケース(通過数/総数)
2/2
状態
メモリ使用量
データパターン1
AC
84 MB
データパターン2
AC
85 MB