ソースコード
with t1 as(
    select
        substr(SALES_DATE, 1, 7) as YEAR_MONTH,
        SALES_AMT as AMT
    from
        SALES
    where
        UPDATED_NO is null
    order by
        YEAR_MONTH
),
t2 as(
    select
        YEAR_MONTH,
        sum(AMT) as AMT
    from
        t1
    group by
        YEAR_MONTH
),
t3 as (
    select
        YEAR_MONTH,
        AMT,
        rank() over(
            order by
                YEAR_MONTH
        ) as RANK
    from
        t2
),
t4 as (
    select
        t.YEAR_MONTH as YEAR_MONTH,
        t.AMT as AMT,
        sum(
            case
                when "2023-01" <= t3.YEAR_MONTH
                and t3.RANK <= t.RANK then t3.AMT
                else 0
            end
        ) as CUML_AMT,
        sum(
            case
                when (t.RANK -11) <= t3.RANK
                and t3.RANK <= t.RANK then t3.AMT
                else 0
            end
        ) as YEAR_MOVE_AMT
    from
        t3 as t,
        t3
    group by
        t.YEAR_MONTH
)
select
    *
from
    t4
where
    "2023-01" <= YEAR_MONTH
    and YEAR_MONTH <= "2023-12"
order by
    YEAR_MONTH
提出情報
提出日時2024/02/19 04:12:35
コンテスト第11回 SQLコンテスト
問題Zチャート
受験者shogo314
状態 (詳細)WA
(Wrong Answer: 誤答)
メモリ使用量85 MB
メッセージ
テストケース(通過数/総数)
0/2
状態
メモリ使用量
データパターン1
WA
85 MB
データパターン2
WA
85 MB