ソースコード
with zzz as (
          select * from MRR_DATA
    union SELECT
              date(MIN(MONTHLY), '-1 months')  as MONTHLY
            , 0 as NEW_MRR
            , 0 as EXPANSION_MRR
            , 0 as DOWNGRADE_MRR
            , 0 as CHURN_MRR
          FROM
              MRR_DATA
    union SELECT
              date(MAX(MONTHLY), '+1 months')  as MONTHLY
            , 0 as NEW_MRR
            , 0 as EXPANSION_MRR
            , 0 as DOWNGRADE_MRR
            , 0 as CHURN_MRR
          FROM
              MRR_DATA
)
, aaa as (
    SELECT
          lead(MONTHLY)       over(order by MONTHLY asc) as YM
      ,   sum(NEW_MRR)       over(order by MONTHLY asc)
        + sum(EXPANSION_MRR) over(order by MONTHLY asc)
        - sum(DOWNGRADE_MRR) over(order by MONTHLY asc)
        - sum(CHURN_MRR)     over(order by MONTHLY asc)
        as MRR
    FROM
        zzz
    ORDER BY
        YM asc
)
select
    YM
  , MRR
from
    aaa
where
    YM is not null
;
提出情報
提出日時2023/02/20 03:16:15
コンテスト第5回 SQLコンテスト
問題MRRの集計
受験者kamaoda
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量79 MB
メッセージ
テストケース(通過数/総数)
3/3
状態
メモリ使用量
データパターン1
AC
79 MB
データパターン2
AC
78 MB
データパターン3
AC
78 MB