ソースコード
with zzz as (
select
  *
from MRR_DATA
 union all
 select
   date(MONTHLY, '+1 months', 'start of month')
  ,0,0,0,0
from MRR_DATA
where MONTHLY = (select MAX(MONTHLY) from MRR_DATA)
)
, aaa as (
select
  *
 ,LAG (NEW_MRR, 1, 0) OVER (ORDER BY MONTHLY) AS LAG_NEW_MRR
 ,LAG (EXPANSION_MRR, 1, 0) OVER (ORDER BY MONTHLY) AS LAG_EXPANSION_MRR
 ,LAG (DOWNGRADE_MRR, 1, 0) OVER (ORDER BY MONTHLY) AS LAG_DOWNGRADE_MRR
 ,LAG (CHURN_MRR, 1, 0) OVER (ORDER BY MONTHLY) AS LAG_CHURN_MRR
from zzz
)
, bbb as (
  select
  *, LAG_NEW_MRR+LAG_EXPANSION_MRR-LAG_DOWNGRADE_MRR-LAG_CHURN_MRR as aaa
  from
  aaa
)
select
MONTHLY as YM,
  SUM(aaa) OVER (
    ORDER BY
      MONTHLY ASC
      ROWS BETWEEN UNBOUNDED  PRECEDING AND CURRENT ROW
  ) AS MRR
from bbb
order by MONTHLY
提出情報
提出日時2023/02/19 16:23:22
コンテスト第5回 SQLコンテスト
問題MRRの集計
受験者kon-kitsune
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量93 MB
メッセージ
テストケース(通過数/総数)
3/3
状態
メモリ使用量
データパターン1
AC
93 MB
データパターン2
AC
87 MB
データパターン3
AC
91 MB