ソースコード
select
    t1.MONTHLY as YM
    ,sum(t2.conMRR) over(order by t1.MONTHLY range between UNBOUNDED PRECEDING and 1 PRECEDING) as MRR
from (
    select MONTHLY, NEW_MRR, EXPANSION_MRR, DOWNGRADE_MRR, CHURN_MRR
                ,(NEW_MRR + EXPANSION_MRR - DOWNGRADE_MRR - CHURN_MRR) as conMRR from MRR_DATA
    union all
    select 
        date(max(MONTHLY), '+1 months') as MONTHLY
        ,0 as NEW_MRR
        ,0 as EXPANSION_MRR
        ,0 as DOWNGRADE_MRR
        ,0 as CHURN_MRR
        ,0 as conMRR
    from MRR_DATA ) t1
        join (
            select MONTHLY, NEW_MRR, EXPANSION_MRR, DOWNGRADE_MRR, CHURN_MRR
                ,(NEW_MRR + EXPANSION_MRR - DOWNGRADE_MRR - CHURN_MRR) as conMRR
            from MRR_DATA
            union all
            select 
                date(min(MONTHLY), '-1 months') as MONTHLY
                ,0 as NEW_MRR
                ,0 as EXPANSION_MRR
                ,0 as DOWNGRADE_MRR
                ,0 as CHURN_MRR
                ,0 as conMRR
            from MRR_DATA
            ) t2
            on t1.MONTHLY = date(t2.MONTHLY, '+1 months')
order by t1.MONTHLY
提出情報
提出日時2023/02/19 19:29:41
コンテスト第5回 SQLコンテスト
問題MRRの集計
受験者S_Katou
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量85 MB
メッセージ
テストケース(通過数/総数)
3/3
状態
メモリ使用量
データパターン1
AC
81 MB
データパターン2
AC
85 MB
データパターン3
AC
85 MB