ソースコード
WITH YEAR_BASE AS (
SELECT DISTINCT SUBSTR(SALES_DATE,1,7) AS YEAR_MONTH,
                SUBSTR( DATETIME(DATE(SALES_DATE),'-11 months'),1,7) AS ST_MONTH,
                SUBSTR( DATETIME(DATE(SALES_DATE),'-1 months'),1,7) AS ED_MONTH
  FROM SALES
 WHERE SUBSTR(SALES_DATE,1,7) BETWEEN '2023-01' AND '2023-12'
 ),
 MOVE_YEAR AS (SELECT YEAR_MONTH,
         SUM(SALES_AMT) AS SALES_MONTH
    FROM SALES,YEAR_BASE
   WHERE SUBSTR(SALES_DATE,1,7) BETWEEN ST_MONTH AND ED_MONTH
     AND UPDATED_NO IS NULL
   GROUP BY YEAR_MONTH
 )
SELECT MONTH.YEAR_MONTH AS YEAR_MONTH,
       MONTH.MONTH_AMT AS MONTH_AMT,
       MONTH.CUML_AMT AS CUML_AMT,
       (MONTH.MONTH_AMT + MY.SALES_MONTH) AS YEAR_MOVE_AMT
  FROM (SELECT BASE.MONTH AS YEAR_MONTH,
               BASE.TOTAL_SALES AS MONTH_AMT,
               SUM(CUML.TOTAL_SALES) AS CUML_AMT
          FROM (SELECT SUBSTR(SALES_DATE,1,7) AS MONTH,
                       SUM(SALES_AMT) AS TOTAL_SALES
                  FROM SALES
                 WHERE UPDATED_NO IS NULL
                   AND SUBSTR(SALES_DATE,1,7) BETWEEN '2023-01' AND '2023-12'
                 GROUP BY SUBSTR(SALES_DATE,1,7)
                )  BASE INNER JOIN (SELECT SUBSTR(SALES_DATE,1,7) AS MONTH,
                                           SUM(SALES_AMT) AS TOTAL_SALES
                                      FROM SALES
                                     WHERE UPDATED_NO IS NULL
                                       AND SUBSTR(SALES_DATE,1,7) BETWEEN '2023-01' AND '2023-12'
                                     GROUP BY SUBSTR(SALES_DATE,1,7)
                                   ) CUML
                            ON BASE.MONTH >= CUML.MONTH
          GROUP BY  BASE.MONTH,BASE.TOTAL_SALES
        ) MONTH INNER JOIN MOVE_YEAR MY
                   ON MONTH.YEAR_MONTH = MY.YEAR_MONTH
 ORDER BY YEAR_MONTH
                   
提出情報
提出日時2024/02/16 17:50:37
コンテスト第11回 SQLコンテスト
問題Zチャート
受験者yng
状態 (詳細)WA
(Wrong Answer: 誤答)
メモリ使用量93 MB
メッセージ
テストケース(通過数/総数)
1/2
状態
メモリ使用量
データパターン1
AC
93 MB
データパターン2
WA
84 MB