ソースコード
with a as (
select * from MRR_DATA
union all
select 
 date(max(MONTHLY),'+1 months'),0,0,0,0 
from MRR_DATA
)
select 
    MONTHLY as YM,
    CASE 
        WHEN lag(MONTHLY) OVER(order by MONTHLY) != date(MONTHLY,'-1 months') THEN 0
        ELSE 
    coalesce(sum(NEW_MRR) OVER (ORDER BY MONTHLY rows between unbounded preceding and 1 preceding)  
    + sum(EXPANSION_MRR) OVER (ORDER BY MONTHLY rows between unbounded preceding and 1 preceding)
    - sum(DOWNGRADE_MRR) OVER (ORDER BY MONTHLY rows between unbounded preceding and 1 preceding)
    - sum(CHURN_MRR) OVER (ORDER BY MONTHLY rows between unbounded preceding and 1 preceding), 0) 
    END MRR
from a
order by 1
提出情報
提出日時2023/02/17 16:41:35
コンテスト第5回 SQLコンテスト
問題MRRの集計
受験者skryoooo
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量97 MB
メッセージ
テストケース(通過数/総数)
3/3
状態
メモリ使用量
データパターン1
AC
82 MB
データパターン2
AC
81 MB
データパターン3
AC
97 MB